【发布时间】:2013-07-03 09:31:00
【问题描述】:
我想为我表单的所有 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)
我不知道它出了什么问题... :(
【问题讨论】:
-
不起作用并不能告诉我们任何事情。你的意思是什么不起作用 - 它什么都不做,它是否抛出异常等等。
-
为什么你认为有问题?当您尝试运行代码时会发生什么,这与您的预期有何不同?您收到任何错误消息吗?
-
它什么也没做,所有的文字都是空白的。
标签: vb.net foreach styles controls typeof