我使用RichTextBox1框,定义了这样的函数
Private Function processmsg(ByVal Msg As String)
RichTextBox1.Text = RichTextBox1.Text & Msg & Chr(13) & Chr(10)
RichTextBox1.Refresh
End Function现在我通过下面调用往RichTextBox1框输出内容,那么我如何设定我要输出内容的颜色,比如向这样的
processmsg ("<font color=red>自行设定的内容,动态变化</font>"),但不能向html那样设置,那么我怎样才能根据我的需要设定要输出文本的颜色

解决方案 »

  1.   

    下面的代码把RichTextBox1文本中的单词Name变成红色:
    Private Sub Command1_Click()
    p = 1
    Do While p <> 0
    p = RichTextBox1.Find("Name", p, , 8)
    If p > 0 Then
    RichTextBox1.SelStart = p
    RichTextBox1.SelLength = 4
    RichTextBox1.SelColor = vbRed
    End Ifp = p + 1
    Loop
    End SubPrivate Sub Form_Load()
    RichTextBox1.Text = "UIName=aaa " & vbCrLf & "Name=bbb " & vbCrLf & "Tname=ccc" & vbCrLf & "TnameA=ddd "End Sub
      

  2.   


    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 FunctionPrivate 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变为蓝色,为什么?如何才能实现?
      

  3.   

    Private Function processmsg(ByVal Msg As String, Optional ByVal MsgColor = vbBlack)
    Dim p As Integer
    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 FunctionPrivate Sub Command1_Click()
    processmsg "begin", vbBlack
    processmsg "can't connect ftp server" & Chr(13) & Chr(10), vbRed
    processmsg "china", vbBlue
    End SubPrivate Sub Form_Load()
    RichTextBox1.Text =  "begin" & vbCrLf & "can't connect ftp server" & vbCrLf & "china"
    End Sub