Skip to main content
 首页 » 编程设计

c#之从文本框中删除特定文本

2024年02月20日13artech

在我的应用程序中,我通过命令提示符窗口设置了一个 vpn 连接,输出将放在一个文本框中。它会自行刷新,因此当它从命令提示符处获取一行时会添加一个新行。

输出将是这样的。

> Microsoft Windows [versie 6.1.7601] Copyright (c) 2009 Microsoft 
> Corporation. Alle rechten voorbehouden. 
>  
> C:\Users\...\Desktop>rasdial.exe VPN username password 
> Verbinding maken met VPN... 
> Gebruikersnaam en wachtwoord controleren... 
> Uw computer wordt in het netwerk geregistreerd... 
> Verbinding gemaakt met VPN Opdracht voltooid. 
>  
> C:\Users\Helpdesk\Desktop>exit 

我怎样才能删除 Microsoft Windows 部分,所以我只有这个。

rasdial.exe VPN username password 
Verbinding maken met VPN... 
Gebruikersnaam en wachtwoord controleren... 
Uw computer wordt in het netwerk geregistreerd... 
Verbinding gemaakt met VPN Opdracht voltooid. 

这是我添加单独行的代码。

private void ConnectVPN() 
    { 
        CheckForIllegalCrossThreadCalls = false; 
        Process CMDprocess = new Process(); 
        System.Diagnostics.ProcessStartInfo StartInfo = new System.Diagnostics.ProcessStartInfo(); 
        StartInfo.FileName = "cmd"; 
        StartInfo.CreateNoWindow = true; 
        StartInfo.RedirectStandardInput = true; 
        StartInfo.RedirectStandardOutput = true; 
        StartInfo.UseShellExecute = false; 
        CMDprocess.StartInfo = StartInfo; 
        CMDprocess.Start(); 
        System.IO.StreamReader SR = CMDprocess.StandardOutput; 
        System.IO.StreamWriter SW = CMDprocess.StandardInput; 
        SW.WriteLine("rasdial.exe " + comboBox1.Text + " " + loginText.Text + " " + wachtwoordText.Text); 
        SW.WriteLine("exit"); 
        string line = null; 
        do 
        { 
            line = SR.ReadLine(); 
            if ((line != null)) 
            { 
                VerbindingOutput.Text = VerbindingOutput.Text + line + Environment.NewLine; 
            } 
        } while (!(line == null)); 
    } 

请您参考如下方法:

直接启动 rasdial 进程,然后使用 Arguments 属性将命令行参数传递给它:

StartInfo.Arguments = comboBox1.Text + " " + loginText.Text + " " + wachtwoordText.Text;