0

好吧,我想为我表单的所有 RichTextBox 创建一个全局样式:

和:

Public Class RichTextLabel

Public Shared Sub AddTextWithFont(ByVal sText As String, ByVal oFont As Font)

    For Each cControl In frmMain.Controls
        If (TypeOf cControl Is RichTextBox) Then
            Dim index As Integer
            index = cControl.TextLength
            cControl.AppendText(sText)
            cControl.SelectionStart = index
            cControl.SelectionLength = cControl.TextLength - index
            cControl.SelectionFont = oFont
        End If
    Next
End Sub

Public Shared Sub AddTextWithColor(ByVal sText As String, ByVal oColor As Color)

    For Each cControl In frmMain.Controls
        If (TypeOf cControl Is RichTextBox) Then
            Dim index As Integer
            index = cControl.TextLength
            cControl.AppendText(sText)
            cControl.SelectionStart = index
            cControl.SelectionLength = cControl.TextLength - index
            cControl.SelectionColor = oColor
        End If
    Next
End Sub

结束类

和:

    RichTextLabel.AddTextWithFont("Estado del Spammer: ", New Font("Microsoft Sans Serif", 8, FontStyle.Bold))
    RichTextLabel.AddTextWithColor(state, Color.Red)

我不知道它出了什么问题... :(

4

2 回答 2

0

我解决它:

Public Class RichTextLabel

Public Shared Sub AddTextWithFont(ByVal sText As String, ByVal oFont As Font, ByVal rtb As RichTextBox)

    Dim index As Integer
    index = rtb.TextLength
    rtb.AppendText(sText)
    rtb.SelectionStart = index
    rtb.SelectionLength = rtb.TextLength - index
    rtb.SelectionFont = oFont

End Sub

Public Shared Sub AddTextWithColor(ByVal sText As String, ByVal oColor As Color, ByVal rtb As RichTextBox)

    Dim index As Integer
    index = rtb.TextLength
    rtb.AppendText(sText)
    rtb.SelectionStart = index
    rtb.SelectionLength = rtb.TextLength - index
    rtb.SelectionColor = oColor
End Sub
End Class

和:

RichTextLabel.AddTextWithFont("Estado del Spammer: ", New Font("Microsoft Sans Serif", 8, FontStyle.Bold), RichTextBox1)
RichTextLabel.AddTextWithColor(state, Color.Red, RichTextBox1)
于 2013-07-05T10:29:46.427 回答
0

这似乎有效:

    For Each cControl As Control In frmMain.Controls
        If (TypeOf cControl Is RichTextBox) Then
            Dim rtb As RichTextBox = CType(cControl, RichTextBox)

            Dim index As Integer
            index = rtb.TextLength
            rtb.AppendText(sText)
            rtb.SelectionStart = index
            rtb.SelectionLength = rtb.TextLength - index
            rtb.SelectionFont = oFont
        End If
    Next
于 2013-07-05T10:15:49.650 回答