Visual C#.Net Tutorial

Define Visual C#.Net

C# Label Control

C# TextBox Control

C# Button Control

C# RadioButton Control

C# CheckBox Control

C# CheckListBox

C# ListBox Control

C# ComboBox Control

C# LinkLabel Control

C# DateTime DataType

C# DateTimePicker

C# NumericUpDown

C# RandomNumber

C# PictureBox

C# ProgressBar

C# Timer Control

C# ToolTip

C# TabControl

C# RichTextBox

C# MessageBox

C# Menu Control

C# Toolbars

C# Dialogs Box

RichTextBox Control in C#.Net

The RichTextBox control is similar to a TextBox control but it allows you to format different parts of the text inside it. The TextBox control is typically used to accept text input from the user while the RichTextBox control is used to show formatted text and save it in Rich Text Format (RTF). Common Properties are:
CanRedo - Specifies a whether there are actions that have occurred within the RichTextBox that can be reapplied.
CanUndo - Specifies whether the user can undo the operations done in a RichTextBox control.
DetectUrls - Specifies whether to automatically detect and add the target link to urls inside the RichTextBox control.
Scrollbars - Specifies the type of scrollbars to display.
Text - The text inside the RichTextBox control.
TextLength - Specifies the length of the textbox.
WordWrap - Specifies whether to wrap the text inside the RichTextBox control.

Common Events are:
LinkClicked Occurs when a link was clicked.
Protected Occurs when the user attempts to modified a protected text.
TextChanged Occurs when the text inside the RichTextBox is modified.
SelectionChanged Occurs when the selected text is changed.

Common Methods are:
Append: RichTextBox1.AppendText(" Appended text");
Clear: RichTextBox1.Clear();
Contents: string RichTextBoxContents = dynamicRichTextBox.Text;
Copy: RichTextBox1.Copy();
Cut: RichTextBox1.Cut();
DeselectAll: RichTextBox1.DeselectAll();
Drag-Drop: dynamicRichTextBox.EnableAutoDragDrop = true;
Font: dynamicRichTextBox.Font = new Font("Georgia", 16);
Length: int size = dynamicRichTextBox.TextLength;
MaxLength: dynamicRichTextBox.MaxLength = 50;
Paste: RichTextBox1.Paste();
ReadOnly: dynamicRichTextBox.ReadOnly = true;
ScrollBar: dynamicRichTextBox.ScrollBars = RichTextBoxScrollBars.Both;
SelectAll: RichTextBox1.SelectAll();
SelectionColor: richTextBox1.SelectionColor = Color.Red;
SelectionBackColor: richTextBox1.SelectionBackColor = Color.Yellow;
Shortcuts: dynamicRichTextBox.ShortcutsEnabled = false;
Undo: RichTextBox1.Undo();
Word Wrap: dynamicRichTextBox.WordWrap = true;

Load and Save RTF Files private void LoadRTFButton_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.InitialDirectory = "c:\\"; ofd.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; ofd.FilterIndex = 2; ofd.RestoreDirectory = true; if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { dynamicRichTextBox.LoadFile(ofd.FileName); dynamicRichTextBox.Find("Text", RichTextBoxFinds.MatchCase); dynamicRichTextBox.SelectionFont= new Font("Verdana",12, FontStyle.Bold); dynamicRichTextBox.SelectionColor = Color.Red; dynamicRichTextBox.SaveFile(@"C:\Junk\SavedRTF.rtf", RichTextBoxStreamType.RichText); } }