主题:[讨论]使用RichTextBox1框,根据我的需要设定要输出文本的颜色
Private Function processmsg(ByVal Msg As String, Optional ByVal MsgColor = vbBlack)
Dim p As Integer
RichTextBox1.Text = RichTextBox1.Text & Msg & Chr(13) & Chr(10)
p = 1
Msg = Replace(Msg, Chr(13), "")
Msg = Replace(Msg, Chr(10), "")
Do While p <> 0
p = RichTextBox1.Find(Msg, p, , 8)
If p > 0 Then
RichTextBox1.SelStart = p
RichTextBox1.SelLength = Len(Msg)
RichTextBox1.SelColor = MsgColor
End If
p = p + 1
Loop
End Function
Private Sub Command1_Click()
processmsg "begin", vbBlack
processmsg "can't connect ftp server" & Chr(13) & Chr(10), vbRed
processmsg "china", vbBlue
End Sub
我想can't connect ftp server为红色,china为蓝色,但执行Command1_Click后只有china变为蓝色,为什么?如何才能实现?
Dim p As Integer
RichTextBox1.Text = RichTextBox1.Text & Msg & Chr(13) & Chr(10)
p = 1
Msg = Replace(Msg, Chr(13), "")
Msg = Replace(Msg, Chr(10), "")
Do While p <> 0
p = RichTextBox1.Find(Msg, p, , 8)
If p > 0 Then
RichTextBox1.SelStart = p
RichTextBox1.SelLength = Len(Msg)
RichTextBox1.SelColor = MsgColor
End If
p = p + 1
Loop
End Function
Private Sub Command1_Click()
processmsg "begin", vbBlack
processmsg "can't connect ftp server" & Chr(13) & Chr(10), vbRed
processmsg "china", vbBlue
End Sub
我想can't connect ftp server为红色,china为蓝色,但执行Command1_Click后只有china变为蓝色,为什么?如何才能实现?