vb(在Richtextbox字段中输出加倍)

时间:2013-07-24 07:29:13

标签: vb.net visual-studio-2012 richtextbox

在Visual Studio 2012中使用VB。我无法弄清楚如何清除我需要清除的内容。

请参阅我在下面使用的代码:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

    If RichTextBox1.Text > "" Then
        pingProc.CancelOutputRead()
        'Need Clearing code here
        RichTextBox1.Text = ""
    End If
    Me.Height = 522

    With pingProc.StartInfo
        .FileName = "cmd.exe"
        .Arguments = "/c C:\Tracert.bat"
        .RedirectStandardInput = True
        .RedirectStandardOutput = True
        .UseShellExecute = False
        .CreateNoWindow = True
    End With

    AddHandler pingProc.OutputDataReceived, AddressOf HandleProcessOutput

    pingProc.Start()
    pingProc.BeginOutputReadLine()

End Sub

Private Sub HandleProcessOutput(ByVal sender As Object, ByVal e As System.Diagnostics.DataReceivedEventArgs)
    Me.Invoke(New DelegateAddText(AddressOf AddText), New Object() {e.Data})
End Sub

Delegate Sub DelegateAddText(ByVal Text As String)
Private Sub AddText(ByVal Text As String)
    RichTextBox1.Text &= Text & vbCrLf
End Sub

现在,当我运行此代码时,它运行正常。但我必须再次运行它。当我这样做时,我会根据我运行此代码的次数来获得两份或更多份副本。

首先运行:

Performing Trace Route to 198.224.169.244
Tracing route to 244.sub-198-224-169.myvzw.com [198.224.169.244]
over a maximum of 30 hops:

第二轮:

Performing Trace Route to 198.224.169.244
Performing Trace Route to 198.224.169.244
Tracing route to 244.sub-198-224-169.myvzw.com [198.224.169.244]
Tracing route to 244.sub-198-224-169.myvzw.com [198.224.169.244]
over a maximum of 30 hops:
over a maximum of 30 hops:

1 个答案:

答案 0 :(得分:0)

可能由Addhandler引起......所以,你可以试试这个..

Dim Handled As Boolean

If Not Handled Then 
  AddHandler pingProc.OutputDataReceived, AddressOf HandleProcessOutput
  Handled = True
End If