RichTextBox based Text Editor : RichTextBox « GUI Windows Forms « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

public class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        this.ToolStripComboBoxFonts.SelectedIndex = 0;
    }

    private void MenuItemShowHelpMenu_CheckedChanged(object sender, EventArgs e)
    {
        ToolStripMenuItem item = (ToolStripMenuItem)sender;
        MenuItemHelp.Visible = item.Checked;
    }

    private void MenuItemOpen_Click(object sender, EventArgs e)
    {
        richTextBoxText.LoadFile("Example.rtf");

    }

    private void MenuItemSave_Click(object sender, EventArgs e)
    {
        richTextBoxText.SaveFile("Example.rtf");
    }

    private void MenuItemNew_Click(object sender, EventArgs e)
    {
        richTextBoxText.Text = "";
    }

    private void ToolStripButtonBold_CheckedChanged(object sender, EventArgs e)
    {
        Font oldFont;
        Font newFont;

        bool checkState = ((ToolStripButton)sender).Checked;
        oldFont = this.richTextBoxText.SelectionFont;

        if (!checkState)
            newFont = new Font(oldFont, oldFont.Style & ~FontStyle.Bold);
        else
            newFont = new Font(oldFont, oldFont.Style | FontStyle.Bold);

        this.richTextBoxText.SelectionFont = newFont;
        this.richTextBoxText.Focus();

        this.ToolStripMenuItemBold.CheckedChanged -= new EventHandler(ToolStripMenuItemBold_CheckedChanged);
        this.ToolStripMenuItemBold.Checked = checkState;
        this.ToolStripMenuItemBold.CheckedChanged += new EventHandler(ToolStripMenuItemBold_CheckedChanged);

        if (!checkState)
            toolStripStatusLabelBold.Font = new Font(toolStripStatusLabelBold.Font, toolStripStatusLabelBold.Font.Style & ~FontStyle.Bold);
        else
            toolStripStatusLabelBold.Font = new Font(toolStripStatusLabelBold.Font, toolStripStatusLabelBold.Font.Style | FontStyle.Bold);
    }

    private void ToolStripButtonItalic_CheckedChanged(object sender, EventArgs e)
    {
        Font oldFont;
        Font newFont;

        bool checkState = ((ToolStripButton)sender).Checked;

        oldFont = this.richTextBoxText.SelectionFont;

        if (!checkState)
            newFont = new Font(oldFont, oldFont.Style & ~FontStyle.Italic);
        else
            newFont = new Font(oldFont, oldFont.Style | FontStyle.Italic);

        this.richTextBoxText.SelectionFont = newFont;
        this.richTextBoxText.Focus();

        this.ToolStripMenuItemItalic.CheckedChanged -= new EventHandler(ToolStripMenuItemItalic_CheckedChanged);
        this.ToolStripMenuItemItalic.Checked = checkState;
        this.ToolStripMenuItemItalic.CheckedChanged += new EventHandler(ToolStripMenuItemItalic_CheckedChanged);

        if (!checkState)
            toolStripStatusLabelItalic.Font = new Font(toolStripStatusLabelItalic.Font, toolStripStatusLabelItalic.Font.Style & ~FontStyle.Italic);
        else
            toolStripStatusLabelItalic.Font = new Font(toolStripStatusLabelItalic.Font, toolStripStatusLabelItalic.Font.Style | FontStyle.Italic);
    }

    private void ToolStripButtonUnderline_CheckedChanged(object sender, EventArgs e)
    {
        Font oldFont;
        Font newFont;

        bool checkState = ((ToolStripButton)sender).Checked;

        oldFont = this.richTextBoxText.SelectionFont;

        if (!checkState)
            newFont = new Font(oldFont, oldFont.Style & ~FontStyle.Underline);
        else
            newFont = new Font(oldFont, oldFont.Style | FontStyle.Underline);

        this.richTextBoxText.SelectionFont = newFont;
        this.richTextBoxText.Focus();

        this.ToolStripMenuItemUnderline.CheckedChanged -= new EventHandler(ToolStripMenuItemUnderline_CheckedChanged);
        this.ToolStripMenuItemUnderline.Checked = checkState;
        this.ToolStripMenuItemUnderline.CheckedChanged += new EventHandler(ToolStripMenuItemUnderline_CheckedChanged);
        toolStripStatusLabelUnderline.Enabled = checkState;

        if (!checkState)
            toolStripStatusLabelUnderline.Font = new Font(toolStripStatusLabelUnderline.Font, toolStripStatusLabelUnderline.Font.Style & ~FontStyle.Underline);
        else
            toolStripStatusLabelUnderline.Font = new Font(toolStripStatusLabelUnderline.Font, toolStripStatusLabelUnderline.Font.Style | FontStyle.Underline);
    }

    private void ToolStripMenuItemBold_CheckedChanged(object sender, EventArgs e)
    {
        this.ToolStripButtonBold.Checked = ToolStripMenuItemBold.Checked;
    }

    private void ToolStripMenuItemItalic_CheckedChanged(object sender, EventArgs e)
    {
        this.ToolStripButtonItalic.Checked = ToolStripMenuItemItalic.Checked;
    }

    private void ToolStripMenuItemUnderline_CheckedChanged(object sender, EventArgs e)
    {
        this.ToolStripButtonUnderline.Checked = ToolStripMenuItemUnderline.Checked;
    }

    private void ToolStripComboBoxFonts_SelectedIndexChanged(object sender, EventArgs e)
    {
        string text = ((ToolStripComboBox)sender).SelectedItem.ToString();
        Font newFont = null;

        if (richTextBoxText.SelectionFont == null)
            newFont = new Font(text, richTextBoxText.Font.Size);
        else
            newFont = new Font(text, richTextBoxText.SelectionFont.Size,
                                  richTextBoxText.SelectionFont.Style);
        richTextBoxText.SelectionFont = newFont;
    }

    private void richTextBoxText_TextChanged(object sender, EventArgs e)
    {
        toolStripStatusLabelText.Text = "Number of characters: " + richTextBoxText.Text.Length;
    }

    private void toolStripStatusLabelBold_Click(object sender, EventArgs e)
    {
        this.ToolStripButtonBold.Checked = !ToolStripMenuItemBold.Checked;
    }

    private void toolStripStatusLabelItalic_Click(object sender, EventArgs e)
    {
        this.ToolStripButtonItalic.Checked = !ToolStripMenuItemItalic.Checked;
    }

    private void toolStripStatusLabelUnderline_Click(object sender, EventArgs e)
    {
        this.ToolStripButtonUnderline.Checked = !ToolStripMenuItemUnderline.Checked;
    }
    private void InitializeComponent()
    {

        this.menuStrip1 = new System.Windows.Forms.MenuStrip();
        this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
        this.MenuItemNew = new System.Windows.Forms.ToolStripMenuItem();
        this.MenuItemOpen = new System.Windows.Forms.ToolStripMenuItem();
        this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator();
        this.MenuItemSave = new System.Windows.Forms.ToolStripMenuItem();
        this.saveAsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
        this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator();
        this.printToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
        this.printPreviewToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
        this.toolStripMenuItem3 = new System.Windows.Forms.ToolStripSeparator();
        this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
        this.formatToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
        this.ToolStripMenuItemBold = new System.Windows.Forms.ToolStripMenuItem();
        this.ToolStripMenuItemItalic = new System.Windows.Forms.ToolStripMenuItem();
        this.ToolStripMenuItemUnderline = new System.Windows.Forms.ToolStripMenuItem();
        this.MenuItemHelp = new System.Windows.Forms.ToolStripMenuItem();
        this.contentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
        this.indexToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
        this.searchToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
        this.toolStripMenuItem4 = new System.Windows.Forms.ToolStripSeparator();
        this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
        this.richTextBoxText = new System.Windows.Forms.RichTextBox();
        this.toolStrip1 = new System.Windows.Forms.ToolStrip();
        this.newToolStripButton = new System.Windows.Forms.ToolStripButton();
        this.openToolStripButton = new System.Windows.Forms.ToolStripButton();
        this.saveToolStripButton = new System.Windows.Forms.ToolStripButton();
        this.printToolStripButton = new System.Windows.Forms.ToolStripButton();
        this.toolStripSeparator = new System.Windows.Forms.ToolStripSeparator();
        this.ToolStripButtonBold = new System.Windows.Forms.ToolStripButton();
        this.ToolStripButtonItalic = new System.Windows.Forms.ToolStripButton();
        this.ToolStripButtonUnderline = new System.Windows.Forms.ToolStripButton();
        this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
        this.ToolStripComboBoxFonts = new System.Windows.Forms.ToolStripComboBox();
        this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
        this.helpToolStripButton = new System.Windows.Forms.ToolStripButton();
        this.statusStrip1 = new System.Windows.Forms.StatusStrip();
        this.toolStripStatusLabelText = new System.Windows.Forms.ToolStripStatusLabel();
        this.toolStripStatusLabelBold = new System.Windows.Forms.ToolStripStatusLabel();
        this.toolStripStatusLabelItalic = new System.Windows.Forms.ToolStripStatusLabel();
        this.toolStripStatusLabelUnderline = new System.Windows.Forms.ToolStripStatusLabel();
        this.menuStrip1.SuspendLayout();
        this.toolStrip1.SuspendLayout();
        this.statusStrip1.SuspendLayout();
        this.SuspendLayout();

        this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.fileToolStripMenuItem,
            this.formatToolStripMenuItem,
            this.MenuItemHelp});
        this.menuStrip1.Location = new System.Drawing.Point(0, 0);
        this.menuStrip1.Size = new System.Drawing.Size(454, 24);
        this.menuStrip1.TabIndex = 0;
        this.menuStrip1.Text = "menuStrip1";
        // 

        this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.MenuItemNew,
            this.MenuItemOpen,
            this.toolStripMenuItem1,
            this.MenuItemSave,
            this.saveAsToolStripMenuItem,
            this.toolStripMenuItem2,
            this.printToolStripMenuItem,
            this.printPreviewToolStripMenuItem,
            this.toolStripMenuItem3,
            this.exitToolStripMenuItem});
        this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
        this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
        this.fileToolStripMenuItem.Text = "&File";
        // 
        // MenuItemNew
        // 
        this.MenuItemNew.Name = "MenuItemNew";
        this.MenuItemNew.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.N)));
        this.MenuItemNew.Size = new System.Drawing.Size(146, 22);
        this.MenuItemNew.Text = "&New";
        this.MenuItemNew.Click += new System.EventHandler(this.MenuItemNew_Click);

        this.MenuItemOpen.Name = "MenuItemOpen";
        this.MenuItemOpen.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O)));
        this.MenuItemOpen.Size = new System.Drawing.Size(146, 22);
        this.MenuItemOpen.Text = "&Open";
        this.MenuItemOpen.Click += new System.EventHandler(this.MenuItemOpen_Click);

        this.toolStripMenuItem1.Name = "toolStripMenuItem1";
        this.toolStripMenuItem1.Size = new System.Drawing.Size(143, 6);

        this.MenuItemSave.Name = "MenuItemSave";
        this.MenuItemSave.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.S)));
        this.MenuItemSave.Size = new System.Drawing.Size(146, 22);
        this.MenuItemSave.Text = "&Save";
        this.MenuItemSave.Click += new System.EventHandler(this.MenuItemSave_Click);

        this.saveAsToolStripMenuItem.Name = "saveAsToolStripMenuItem";
        this.saveAsToolStripMenuItem.Size = new System.Drawing.Size(146, 22);
        this.saveAsToolStripMenuItem.Text = "Save &As";
        // 
        // toolStripMenuItem2
        // 
        this.toolStripMenuItem2.Name = "toolStripMenuItem2";
        this.toolStripMenuItem2.Size = new System.Drawing.Size(143, 6);
        // 
        // printToolStripMenuItem
        // 
        this.printToolStripMenuItem.Name = "printToolStripMenuItem";
        this.printToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.P)));
        this.printToolStripMenuItem.Size = new System.Drawing.Size(146, 22);
        this.printToolStripMenuItem.Text = "&Print";
        // 
        // printPreviewToolStripMenuItem
        // 
        this.printPreviewToolStripMenuItem.Name = "printPreviewToolStripMenuItem";
        this.printPreviewToolStripMenuItem.Size = new System.Drawing.Size(146, 22);
        this.printPreviewToolStripMenuItem.Text = "Print Preview";
        // 
        // toolStripMenuItem3
        // 
        this.toolStripMenuItem3.Name = "toolStripMenuItem3";
        this.toolStripMenuItem3.Size = new System.Drawing.Size(143, 6);
        // 
        // exitToolStripMenuItem
        // 
        this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
        this.exitToolStripMenuItem.Size = new System.Drawing.Size(146, 22);
        this.exitToolStripMenuItem.Text = "E&xit";
        // 
        // formatToolStripMenuItem
        // 
        this.formatToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.ToolStripMenuItemBold,
            this.ToolStripMenuItemItalic,
            this.ToolStripMenuItemUnderline});
        this.formatToolStripMenuItem.Name = "formatToolStripMenuItem";
        this.formatToolStripMenuItem.Size = new System.Drawing.Size(57, 20);
        this.formatToolStripMenuItem.Text = "Format";
        // 
        // ToolStripMenuItemBold
        // 
        this.ToolStripMenuItemBold.CheckOnClick = true;
        this.ToolStripMenuItemBold.Name = "ToolStripMenuItemBold";
        this.ToolStripMenuItemBold.Size = new System.Drawing.Size(125, 22);
        this.ToolStripMenuItemBold.Text = "Bold";
        this.ToolStripMenuItemBold.CheckedChanged += new System.EventHandler(this.ToolStripMenuItemBold_CheckedChanged);
        // 
        // ToolStripMenuItemItalic
        // 
        this.ToolStripMenuItemItalic.CheckOnClick = true;
        this.ToolStripMenuItemItalic.Name = "ToolStripMenuItemItalic";
        this.ToolStripMenuItemItalic.Size = new System.Drawing.Size(125, 22);
        this.ToolStripMenuItemItalic.Text = "Italic";
        this.ToolStripMenuItemItalic.CheckedChanged += new System.EventHandler(this.ToolStripMenuItemItalic_CheckedChanged);
        // 
        // ToolStripMenuItemUnderline
        // 
        this.ToolStripMenuItemUnderline.CheckOnClick = true;
        this.ToolStripMenuItemUnderline.Name = "ToolStripMenuItemUnderline";
        this.ToolStripMenuItemUnderline.Size = new System.Drawing.Size(125, 22);
        this.ToolStripMenuItemUnderline.Text = "Underline";
        this.ToolStripMenuItemUnderline.CheckedChanged += new System.EventHandler(this.ToolStripMenuItemUnderline_CheckedChanged);
        // 
        // MenuItemHelp
        // 
        this.MenuItemHelp.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.contentsToolStripMenuItem,
            this.indexToolStripMenuItem,
            this.searchToolStripMenuItem,
            this.toolStripMenuItem4,
            this.aboutToolStripMenuItem});
        this.MenuItemHelp.Name = "MenuItemHelp";
        this.MenuItemHelp.Size = new System.Drawing.Size(44, 20);
        this.MenuItemHelp.Text = "&Help";
        // 
        // contentsToolStripMenuItem
        // 
        this.contentsToolStripMenuItem.Name = "contentsToolStripMenuItem";
        this.contentsToolStripMenuItem.Size = new System.Drawing.Size(122, 22);
        this.contentsToolStripMenuItem.Text = "Contents";
        // 
        // indexToolStripMenuItem
        // 
        this.indexToolStripMenuItem.Name = "indexToolStripMenuItem";
        this.indexToolStripMenuItem.Size = new System.Drawing.Size(122, 22);
        this.indexToolStripMenuItem.Text = "Index";
        // 
        // searchToolStripMenuItem
        // 
        this.searchToolStripMenuItem.Name = "searchToolStripMenuItem";
        this.searchToolStripMenuItem.Size = new System.Drawing.Size(122, 22);
        this.searchToolStripMenuItem.Text = "Search";
        // 
        // toolStripMenuItem4
        // 
        this.toolStripMenuItem4.Name = "toolStripMenuItem4";
        this.toolStripMenuItem4.Size = new System.Drawing.Size(119, 6);
        // 
        // aboutToolStripMenuItem
        // 
        this.aboutToolStripMenuItem.Name = "aboutToolStripMenuItem";
        this.aboutToolStripMenuItem.Size = new System.Drawing.Size(122, 22);
        this.aboutToolStripMenuItem.Text = "About";
        // 
        // richTextBoxText
        // 
        this.richTextBoxText.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                    | System.Windows.Forms.AnchorStyles.Left)
                    | System.Windows.Forms.AnchorStyles.Right)));
        this.richTextBoxText.Location = new System.Drawing.Point(0, 52);
        this.richTextBoxText.Name = "richTextBoxText";
        this.richTextBoxText.Size = new System.Drawing.Size(454, 212);
        this.richTextBoxText.TabIndex = 1;
        this.richTextBoxText.Text = "";
        this.richTextBoxText.TextChanged += new System.EventHandler(this.richTextBoxText_TextChanged);
        // 
        // toolStrip1
        // 
        this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.newToolStripButton,
            this.openToolStripButton,
            this.saveToolStripButton,
            this.printToolStripButton,
            this.toolStripSeparator,
            this.ToolStripButtonBold,
            this.ToolStripButtonItalic,
            this.ToolStripButtonUnderline,
            this.toolStripSeparator1,
            this.ToolStripComboBoxFonts,
            this.toolStripSeparator2,
            this.helpToolStripButton});
        this.toolStrip1.Location = new System.Drawing.Point(0, 24);
        this.toolStrip1.Name = "toolStrip1";
        this.toolStrip1.Size = new System.Drawing.Size(454, 25);
        this.toolStrip1.TabIndex = 2;
        this.toolStrip1.Text = "toolStrip1";
        // 
        // newToolStripButton
        // 
        this.newToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
        this.newToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta;
        this.newToolStripButton.Name = "newToolStripButton";
        this.newToolStripButton.Size = new System.Drawing.Size(23, 22);
        this.newToolStripButton.Text = "&New";
        this.newToolStripButton.Click += new System.EventHandler(this.MenuItemNew_Click);
        // 
        // openToolStripButton
        // 
        this.openToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
        this.openToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta;
        this.openToolStripButton.Name = "openToolStripButton";
        this.openToolStripButton.Size = new System.Drawing.Size(23, 22);
        this.openToolStripButton.Text = "&Open";
        this.openToolStripButton.Click += new System.EventHandler(this.MenuItemOpen_Click);
        // 
        // saveToolStripButton
        // 
        this.saveToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
        this.saveToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta;
        this.saveToolStripButton.Name = "saveToolStripButton";
        this.saveToolStripButton.Size = new System.Drawing.Size(23, 22);
        this.saveToolStripButton.Text = "&Save";
        this.saveToolStripButton.Click += new System.EventHandler(this.MenuItemSave_Click);
        // 
        // printToolStripButton
        // 
        this.printToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
        this.printToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta;
        this.printToolStripButton.Name = "printToolStripButton";
        this.printToolStripButton.Size = new System.Drawing.Size(23, 22);
        this.printToolStripButton.Text = "&Print";
        // 
        // toolStripSeparator
        // 
        this.toolStripSeparator.Name = "toolStripSeparator";
        this.toolStripSeparator.Size = new System.Drawing.Size(6, 25);
        // 
        // ToolStripButtonBold
        // 
        this.ToolStripButtonBold.CheckOnClick = true;
        this.ToolStripButtonBold.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
        this.ToolStripButtonBold.ImageTransparentColor = System.Drawing.Color.Magenta;
        this.ToolStripButtonBold.Name = "ToolStripButtonBold";
        this.ToolStripButtonBold.Size = new System.Drawing.Size(23, 22);
        this.ToolStripButtonBold.Text = "toolStripButton1";
        this.ToolStripButtonBold.CheckedChanged += new System.EventHandler(this.ToolStripButtonBold_CheckedChanged);
        // 
        // ToolStripButtonItalic
        // 
        this.ToolStripButtonItalic.CheckOnClick = true;
        this.ToolStripButtonItalic.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
        this.ToolStripButtonItalic.ImageTransparentColor = System.Drawing.Color.Magenta;
        this.ToolStripButtonItalic.Name = "ToolStripButtonItalic";
        this.ToolStripButtonItalic.Size = new System.Drawing.Size(23, 22);
        this.ToolStripButtonItalic.Text = "toolStripButton2";
        this.ToolStripButtonItalic.CheckedChanged += new System.EventHandler(this.ToolStripButtonItalic_CheckedChanged);
        // 
        // ToolStripButtonUnderline
        // 
        this.ToolStripButtonUnderline.CheckOnClick = true;
        this.ToolStripButtonUnderline.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
        this.ToolStripButtonUnderline.ImageTransparentColor = System.Drawing.Color.Magenta;
        this.ToolStripButtonUnderline.Name = "ToolStripButtonUnderline";
        this.ToolStripButtonUnderline.Size = new System.Drawing.Size(23, 22);
        this.ToolStripButtonUnderline.Text = "toolStripButton3";
        this.ToolStripButtonUnderline.CheckedChanged += new System.EventHandler(this.ToolStripButtonUnderline_CheckedChanged);
        // 
        // toolStripSeparator1
        // 
        this.toolStripSeparator1.Name = "toolStripSeparator1";
        this.toolStripSeparator1.Size = new System.Drawing.Size(6, 25);
        // 
        // ToolStripComboBoxFonts
        // 
        this.ToolStripComboBoxFonts.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
        this.ToolStripComboBoxFonts.Items.AddRange(new object[] {
            "MS Sans Serif",
            "Times New Roman"});
        this.ToolStripComboBoxFonts.Name = "ToolStripComboBoxFonts";
        this.ToolStripComboBoxFonts.Size = new System.Drawing.Size(121, 25);
        this.ToolStripComboBoxFonts.SelectedIndexChanged += new System.EventHandler(this.ToolStripComboBoxFonts_SelectedIndexChanged);
        // 
        // toolStripSeparator2
        // 
        this.toolStripSeparator2.Name = "toolStripSeparator2";
        this.toolStripSeparator2.Size = new System.Drawing.Size(6, 25);
        // 
        // helpToolStripButton
        // 
        this.helpToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
        this.helpToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta;
        this.helpToolStripButton.Name = "helpToolStripButton";
        this.helpToolStripButton.Size = new System.Drawing.Size(23, 22);
        this.helpToolStripButton.Text = "He&lp";
        // 
        // statusStrip1
        // 
        this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.toolStripStatusLabelText,
            this.toolStripStatusLabelBold,
            this.toolStripStatusLabelItalic,
            this.toolStripStatusLabelUnderline});
        this.statusStrip1.Location = new System.Drawing.Point(0, 242);
        this.statusStrip1.Name = "statusStrip1";
        this.statusStrip1.Size = new System.Drawing.Size(454, 22);
        this.statusStrip1.TabIndex = 3;
        this.statusStrip1.Text = "statusStrip1";
        // 
        // toolStripStatusLabelText
        // 
        this.toolStripStatusLabelText.AutoSize = false;
        this.toolStripStatusLabelText.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
        this.toolStripStatusLabelText.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold);
        this.toolStripStatusLabelText.Name = "toolStripStatusLabelText";
        this.toolStripStatusLabelText.Size = new System.Drawing.Size(259, 17);
        this.toolStripStatusLabelText.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
        // 
        // toolStripStatusLabelBold
        // 
        this.toolStripStatusLabelBold.AutoSize = false;
        this.toolStripStatusLabelBold.DoubleClickEnabled = true;
        this.toolStripStatusLabelBold.Enabled = false;
        this.toolStripStatusLabelBold.Font = new System.Drawing.Font("Arial", 8.25F);
        this.toolStripStatusLabelBold.Name = "toolStripStatusLabelBold";
        this.toolStripStatusLabelBold.Size = new System.Drawing.Size(47, 17);
        this.toolStripStatusLabelBold.Text = "Bold";
        this.toolStripStatusLabelBold.Click += new System.EventHandler(this.toolStripStatusLabelBold_Click);
        // 
        // toolStripStatusLabelItalic
        // 
        this.toolStripStatusLabelItalic.AutoSize = false;
        this.toolStripStatusLabelItalic.DoubleClickEnabled = true;
        this.toolStripStatusLabelItalic.Enabled = false;
        this.toolStripStatusLabelItalic.Font = new System.Drawing.Font("Arial", 8.25F);
        this.toolStripStatusLabelItalic.Name = "toolStripStatusLabelItalic";
        this.toolStripStatusLabelItalic.Size = new System.Drawing.Size(48, 17);
        this.toolStripStatusLabelItalic.Text = "Italic";
        this.toolStripStatusLabelItalic.Click += new System.EventHandler(this.toolStripStatusLabelItalic_Click);
        // 
        // toolStripStatusLabelUnderline
        // 
        this.toolStripStatusLabelUnderline.AutoSize = false;
        this.toolStripStatusLabelUnderline.DoubleClickEnabled = true;
        this.toolStripStatusLabelUnderline.Enabled = false;
        this.toolStripStatusLabelUnderline.Font = new System.Drawing.Font("Arial", 8.25F);
        this.toolStripStatusLabelUnderline.Name = "toolStripStatusLabelUnderline";
        this.toolStripStatusLabelUnderline.Size = new System.Drawing.Size(76, 17);
        this.toolStripStatusLabelUnderline.Text = "Underline";
        this.toolStripStatusLabelUnderline.Click += new System.EventHandler(this.toolStripStatusLabelUnderline_Click);
        // 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(454, 264);
        this.Controls.Add(this.statusStrip1);
        this.Controls.Add(this.toolStrip1);
        this.Controls.Add(this.richTextBoxText);
        this.Controls.Add(this.menuStrip1);
        this.MainMenuStrip = this.menuStrip1;
        this.menuStrip1.ResumeLayout(false);
        this.menuStrip1.PerformLayout();
        this.toolStrip1.ResumeLayout(false);
        this.toolStrip1.PerformLayout();
        this.statusStrip1.ResumeLayout(false);
        this.statusStrip1.PerformLayout();
        this.ResumeLayout(false);
        this.PerformLayout();

    }

    private System.Windows.Forms.MenuStrip menuStrip1;
    private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
    private System.Windows.Forms.ToolStripMenuItem MenuItemNew;
    private System.Windows.Forms.ToolStripMenuItem MenuItemOpen;
    private System.Windows.Forms.ToolStripSeparator toolStripMenuItem1;
    private System.Windows.Forms.ToolStripMenuItem MenuItemSave;
    private System.Windows.Forms.ToolStripMenuItem saveAsToolStripMenuItem;
    private System.Windows.Forms.ToolStripSeparator toolStripMenuItem2;
    private System.Windows.Forms.ToolStripMenuItem printToolStripMenuItem;
    private System.Windows.Forms.ToolStripMenuItem printPreviewToolStripMenuItem;
    private System.Windows.Forms.ToolStripSeparator toolStripMenuItem3;
    private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;
    private System.Windows.Forms.ToolStripMenuItem MenuItemHelp;
    private System.Windows.Forms.ToolStripMenuItem contentsToolStripMenuItem;
    private System.Windows.Forms.ToolStripMenuItem indexToolStripMenuItem;
    private System.Windows.Forms.ToolStripMenuItem searchToolStripMenuItem;
    private System.Windows.Forms.ToolStripSeparator toolStripMenuItem4;
    private System.Windows.Forms.ToolStripMenuItem aboutToolStripMenuItem;
    private System.Windows.Forms.ToolStripMenuItem formatToolStripMenuItem;
    private System.Windows.Forms.RichTextBox richTextBoxText;
    private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItemBold;
    private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItemItalic;
    private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItemUnderline;
    private System.Windows.Forms.ToolStrip toolStrip1;
    private System.Windows.Forms.ToolStripButton newToolStripButton;
    private System.Windows.Forms.ToolStripButton openToolStripButton;
    private System.Windows.Forms.ToolStripButton saveToolStripButton;
    private System.Windows.Forms.ToolStripButton printToolStripButton;
    private System.Windows.Forms.ToolStripSeparator toolStripSeparator;
    private System.Windows.Forms.ToolStripButton ToolStripButtonBold;
    private System.Windows.Forms.ToolStripButton ToolStripButtonItalic;
    private System.Windows.Forms.ToolStripButton ToolStripButtonUnderline;
    private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
    private System.Windows.Forms.ToolStripComboBox ToolStripComboBoxFonts;
    private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
    private System.Windows.Forms.ToolStripButton helpToolStripButton;
    private System.Windows.Forms.StatusStrip statusStrip1;
    private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelText;
    private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelBold;
    private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelItalic;
    private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelUnderline;

    [STAThread]
    static void Main()
    {
        Application.Run(new Form1());
    }
}








23.20.RichTextBox
23.20.1.LoadFile SaveFile
23.20.2.RichTextBox: font
23.20.3.Editor based on RichTextBoxEditor based on RichTextBox
23.20.4.Build Menu for a RichTextBox editorBuild Menu for a RichTextBox editor
23.20.5.RichTextBox based Text Editor