使用 aRichTextBox
时,为什么不直接使用 RTF?
例子:
Sub Main
Dim f = new Form()
Dim print_text = new RichTextBox() With {.Dock = DockStyle.Fill}
f.Controls.Add(print_text)
Dim sb = new System.Text.StringBuilder()
sb.Append("{\rtf1\ansi")
sb.Append("This number is bold: \b 123\b0 ! Yes, it is...")
sb.Append("}")
print_text.Rtf = sb.ToString()
f.ShowDialog()
End Sub
结果:
MSDN
这样,您还可以轻松地将 RTF 内容包装到扩展方法中:
Module RtfExtensions
<Extension()>
Public Function ToRtf(s As String) As String
Return "{\rtf1\ansi" + s + "}"
End Function
<Extension()>
Public Function ToBold(s As String) As String
Return String.Format("\b {0}\b0 ", s)
End Function
End Module
并像使用它一样
Dim text = "This number is bold: " + "123".ToBold() + "! Yes, it is..."
print_text.Rtf = text.ToRtf()