Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Visual Studio
Windows Forms
 How to: Set Font Attributes for the...
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Windows Forms Programming
How to: Set 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 enables you to change the selected characters' color.

To change the appearance of characters

  1. 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 FontDialog Component Overview (Windows Forms).

  2. 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 ColorDialog Component Overview (Windows Forms).

    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;
    

    Visual C++
    richTextBox1->SelectionFont =
       gcnew System::Drawing::Font("Tahoma", 12, FontStyle::Bold);
    richTextBox1->SelectionColor = System::Drawing::Color::Red;
    NoteNote:

    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.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker