我正在开发使用串行通信进行数据传输的软件。我的问题与richtextbox有关,我想在单词“change configuration?”时弹出一个InputBox。出现在richtextbox中。
请帮帮我。
这是我的配置:
Private Sub btnWrEr_Click(sender As Object, e As EventArgs) Handles btnWrEr.Click
SerialPort1.WriteLine("write erase" & vbCr & vbCr & "reload" & vbCr)
If InStr(rtbReceived.Text, "System configuration has been modified. Save? [yes/no]:") Then
Dim save As String
save = InputBox("System configuration has been modified. Save? [yes/no]:", "yes/no")
SerialPort1.WriteLine(save & vbCr)
Else
SerialPort1.Write(vbCr)
End If
End Sub
这是我收到的rtb编码:
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
ReceivedText(SerialPort1.ReadExisting())
End Sub
Private Sub ReceivedText(ByVal [text] As String)
If Me.rtbReceived.InvokeRequired Then
Dim x As New SetTextCallBack(AddressOf ReceivedText)
Me.Invoke(x, New Object() {(text)})
Else
Me.rtbReceived.Text &= [text]
End If
End Sub
Private Sub rtbReceived_TextChanged(sender As Object, e As EventArgs) Handles rtbReceived.TextChanged
rtbReceived.SelectionStart = rtbReceived.TextLength
rtbReceived.ScrollToCaret()
End Sub
答案 0 :(得分:0)
这看起来非常简单,只需将此代码添加到文本更改事件
即可 If RichTextBox1.Text.Contains("change configuration ?") Then
InputString = InputBox("How do you want to change it?")
End If
或代替if..end if语句中的行只调用另一个子