LoadFile SaveFile : RichTextBox « GUI Windows Forms « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » GUI Windows Forms » RichTextBox 
23.20.1.LoadFile SaveFile
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;


public class Form1 : Form {
    public Form1() {
        InitializeComponent();
    }

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

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

    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 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.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
        this.printToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
        this.toolStripMenuItem4 = new System.Windows.Forms.ToolStripMenuItem();
        this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator();
        this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
        this.formatToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
        this.MenuItemShowHelpMenu = 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.toolStripMenuItem3 = new System.Windows.Forms.ToolStripSeparator();
        this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
        this.richTextBoxText = new System.Windows.Forms.RichTextBox();
        this.menuStrip1.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(00);
        this.menuStrip1.Name = "menuStrip1";
        this.menuStrip1.Size = new System.Drawing.Size(60224);
        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.toolStripSeparator1,
            this.printToolStripMenuItem,
            this.toolStripMenuItem4,
            this.toolStripMenuItem2,
            this.exitToolStripMenuItem});
        this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
        this.fileToolStripMenuItem.Size = new System.Drawing.Size(3520);
        this.fileToolStripMenuItem.Text = "&File";

        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(15122);
        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(15122);
        this.MenuItemOpen.Text = "&Open";
        this.MenuItemOpen.Click += new System.EventHandler(this.MenuItemOpen_Click);

        this.toolStripMenuItem1.Name = "toolStripMenuItem1";
        this.toolStripMenuItem1.Size = new System.Drawing.Size(1486);

        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(15122);
        this.MenuItemSave.Text = "&Save";
        this.MenuItemSave.Click += new System.EventHandler(this.MenuItemSave_Click);

        this.saveAsToolStripMenuItem.Name = "saveAsToolStripMenuItem";
        this.saveAsToolStripMenuItem.Size = new System.Drawing.Size(15122);
        this.saveAsToolStripMenuItem.Text = "Save &As";

        this.toolStripSeparator1.Name = "toolStripSeparator1";
        this.toolStripSeparator1.Size = new System.Drawing.Size(1486);

        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(15122);
        this.printToolStripMenuItem.Text = "&Print";

        this.toolStripMenuItem4.Name = "toolStripMenuItem4";
        this.toolStripMenuItem4.Size = new System.Drawing.Size(15122);
        this.toolStripMenuItem4.Text = "Print Preview";

        this.toolStripMenuItem2.Name = "toolStripMenuItem2";
        this.toolStripMenuItem2.Size = new System.Drawing.Size(1486);

        this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
        this.exitToolStripMenuItem.Size = new System.Drawing.Size(15122);
        this.exitToolStripMenuItem.Text = "E&xit";

        this.formatToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.MenuItemShowHelpMenu});
        this.formatToolStripMenuItem.Name = "formatToolStripMenuItem";
        this.formatToolStripMenuItem.Size = new System.Drawing.Size(5320);
        this.formatToolStripMenuItem.Text = "Format";

        this.MenuItemShowHelpMenu.Checked = true;
        this.MenuItemShowHelpMenu.CheckOnClick = true;
        this.MenuItemShowHelpMenu.CheckState = System.Windows.Forms.CheckState.Checked;
        this.MenuItemShowHelpMenu.Name = "MenuItemShowHelpMenu";
        this.MenuItemShowHelpMenu.Size = new System.Drawing.Size(16422);
        this.MenuItemShowHelpMenu.Text = "Show Help Menu";
        this.MenuItemShowHelpMenu.Click += new System.EventHandler(this.MenuItemShowHelpMenu_Click);

        this.MenuItemHelp.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.contentsToolStripMenuItem,
            this.indexToolStripMenuItem,
            this.searchToolStripMenuItem,
            this.toolStripMenuItem3,
            this.aboutToolStripMenuItem});
        this.MenuItemHelp.Name = "MenuItemHelp";
        this.MenuItemHelp.Size = new System.Drawing.Size(4020);
        this.MenuItemHelp.Text = "&Help";

        this.contentsToolStripMenuItem.Name = "contentsToolStripMenuItem";
        this.contentsToolStripMenuItem.Size = new System.Drawing.Size(12922);
        this.contentsToolStripMenuItem.Text = "Contents";

        this.indexToolStripMenuItem.Name = "indexToolStripMenuItem";
        this.indexToolStripMenuItem.Size = new System.Drawing.Size(12922);
        this.indexToolStripMenuItem.Text = "Index";

        this.searchToolStripMenuItem.Name = "searchToolStripMenuItem";
        this.searchToolStripMenuItem.Size = new System.Drawing.Size(12922);
        this.searchToolStripMenuItem.Text = "Search";

        this.toolStripMenuItem3.Name = "toolStripMenuItem3";
        this.toolStripMenuItem3.Size = new System.Drawing.Size(1266);

        this.aboutToolStripMenuItem.Name = "aboutToolStripMenuItem";
        this.aboutToolStripMenuItem.Size = new System.Drawing.Size(12922);
        this.aboutToolStripMenuItem.Text = "About";

        this.richTextBoxText.Dock = System.Windows.Forms.DockStyle.Fill;
        this.richTextBoxText.Location = new System.Drawing.Point(024);
        this.richTextBoxText.Name = "richTextBoxText";
        this.richTextBoxText.Size = new System.Drawing.Size(602242);
        this.richTextBoxText.TabIndex = 1;
        this.richTextBoxText.Text = "";

        this.AutoScaleDimensions = new System.Drawing.SizeF(6F13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(602266);
        this.Controls.Add(this.richTextBoxText);
        this.Controls.Add(this.menuStrip1);
        this.MainMenuStrip = this.menuStrip1;
        this.menuStrip1.ResumeLayout(false);
        this.menuStrip1.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.ToolStripMenuItem printToolStripMenuItem;
    private System.Windows.Forms.ToolStripSeparator toolStripMenuItem2;
    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 toolStripMenuItem3;
    private System.Windows.Forms.ToolStripMenuItem aboutToolStripMenuItem;
    private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
    private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem4;
    private System.Windows.Forms.ToolStripMenuItem formatToolStripMenuItem;
    private System.Windows.Forms.ToolStripMenuItem MenuItemShowHelpMenu;
    private System.Windows.Forms.RichTextBox richTextBoxText;
    [STAThread]
    static void Main() {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.