RichTextBox Constructor
Collapse the table of content
Expand the table of content

RichTextBox Constructor ()


Initializes a new instance of the RichTextBox class.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public RichTextBox()

By default, the Multiline property of the control is set to true.

Legacy Code Example

The following code example creates a RichTextBox control that loads an RTF file into the control and searches for the first instance of the word "Text." The code then changes the font style, font size, and font color of the selected text and saves the changes back to the original file. The example code finishes by adding the control to its Form. This example requires that the method created in the example code is added to a Form class and called from the constructor of the form. The example also requires that an RTF file is created, in the root of the C drive, containing the word "Text."

public void CreateMyRichTextBox()
    RichTextBox richTextBox1 = new RichTextBox();
    richTextBox1.Dock = DockStyle.Fill;

    richTextBox1.Find("Text", RichTextBoxFinds.MatchCase);

    richTextBox1.SelectionFont = new Font("Verdana", 12, FontStyle.Bold);
    richTextBox1.SelectionColor = Color.Red;

    richTextBox1.SaveFile("C:\\MyDocument.rtf", RichTextBoxStreamType.RichText);


.NET Framework
Available since 1.1
Return to top
© 2015 Microsoft