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 ()
public RichTextBox ()
public function RichTextBox ()

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

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.LoadFile("C:\\MyDocument.rtf");
    richTextBox1.Find("Text", RichTextBoxFinds.MatchCase);

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

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

    this.Controls.Add(richTextBox1);
}


public void CreateMyRichTextBox()
{
    RichTextBox richTextBox1 = new RichTextBox();

    richTextBox1.set_Dock(DockStyle.Fill);
    richTextBox1.LoadFile("C:\\MyDocument.rtf");
    richTextBox1.Find("Text", RichTextBoxFinds.MatchCase);
    richTextBox1.set_SelectionFont(new Font
        ("Verdana", 12, FontStyle.Bold));
    richTextBox1.set_SelectionColor(Color.get_Red());
    richTextBox1.SaveFile("C:\\MyDocument.rtf",
        RichTextBoxStreamType.RichText);
    this.get_Controls().Add(richTextBox1);
} //CreateMyRichTextBox

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show: