RichTextBox Constructor ()
.NET Framework (current version)
Initializes a new instance of the RichTextBox class.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
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 = gcnew RichTextBox; richTextBox1->Dock = DockStyle::Fill; richTextBox1->LoadFile( "C:\\MyDocument.rtf" ); richTextBox1->Find( "Text", RichTextBoxFinds::MatchCase ); richTextBox1->SelectionFont = gcnew System::Drawing::Font( "Verdana", 12, FontStyle::Bold ); richTextBox1->SelectionColor = Color::Red; richTextBox1->SaveFile( "C:\\MyDocument.rtf", RichTextBoxStreamType::RichText ); this->Controls->Add( richTextBox1 ); }
.NET Framework
Available since 1.1
Available since 1.1
Show: