好吧,我想为我表单的所有 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)
我不知道它出了什么问题... :(