Setting Font Attributes for the Windows Forms RichTextBox Control
The Windows Forms RichTextBox control has numerous options for formatting the text it displays. You can make the selected characters bold, underlined, or italic, using the SelectionFont property. You can also use this property to change the size and typeface of the selected characters. The SelectionColor property allows you to change the selected characters' color.
To change the appearance of characters
- Set the SelectionFont property to an appropriate font.
To enable users to set the font family, size, and typeface in an application, you would typically use the FontDialog component. For an overview, see Introduction to the Windows Forms FontDialog Component.
- Set the SelectionColor property to an appropriate color.
To enable users to set the color in an application, you would typically use the ColorDialog component. For an overview, see Introduction to the Windows Forms ColorDialog Component.
' Visual Basic RichTextBox1.SelectionFont = New Font("Tahoma", 12, FontStyle.Bold) RichTextBox1.SelectionColor = System.Drawing.Color.Red // C# richTextBox1.SelectionFont = new Font("Tahoma", 12, FontStyle.Bold); richTextBox1.SelectionColor = System.Drawing.Color.Red; // C++ richTextBox1->SelectionFont = new System::Drawing::Font("Tahoma", 12, FontStyle::Bold); richTextBox1->SelectionColor = System::Drawing::Color::Red;
Note These properties only affect selected text, or, if no text is selected, the text that is typed at the current location of the insertion point. For information on selecting text programmatically, see TextBoxBase.Select Method.
See Also
RichTextBox Class | RichTextBox Control (Windows Forms) | Controls You Can Use on Windows Forms
感谢您的阅读。
《ASP.NET MVC 5 破境之道》
《C# 爬虫 破境之道》
《C# GDI+ 破境之道》
持续添加中……
喜欢本系列丛书的朋友,可以点击链接加入QQ交流群(994761602)【C# 破境之道】