Simple Editor based on TextBox : TextBox « GUI Windows Form « C# / C Sharp

C# / C Sharp
1. 2D Graphics
2. Class Interface
3. Collections Data Structure
4. Components
5. Data Types
6. Database ADO.net
7. Design Patterns
8. Development Class
9. Event
10. File Stream
11. Generics
12. GUI Windows Form
13. Language Basics
14. LINQ
15. Network
16. Office
17. Reflection
18. Regular Expressions
19. Security
20. Services Event
21. Thread
22. Web Services
23. Windows
24. XML
25. XML LINQ
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
C# / C Sharp » GUI Windows Form » TextBoxScreenshots 
Simple Editor based on TextBox
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

public class SimpleEditorForm : Form {
    private string filename = "Untitled";

    public SimpleEditorForm(string filename) {
        InitializeComponent();

        if (filename != null) {
            this.filename = filename;
            OpenFile();
        }
    }

    protected void OpenFile() {
        try {
            textBoxEdit.Clear();
            textBoxEdit.Text = File.ReadAllText(filename);
        catch (IOException ex) {
            MessageBox.Show(ex.Message, "Simple Editor",
                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }
    }

    private void OnFileNew(object sender, EventArgs e) {
        filename = "Untitled";
        textBoxEdit.Clear();
    }

    private void OnFileOpen(object sender, EventArgs e) {
        if (dlgOpenFile.ShowDialog() == DialogResult.OK) {
            filename = dlgOpenFile.FileName;
            OpenFile();
        }
    }

    private void OnFileSave(object sender, EventArgs e) {

    }

    private void OnFileSaveAs(object sender, EventArgs e) {

    }
    private void InitializeComponent() {
        this.textBoxEdit = new System.Windows.Forms.TextBox();
        this.mainMenu = new System.Windows.Forms.MenuStrip();
        this.miFile = new System.Windows.Forms.ToolStripMenuItem();
        this.miFileNew = new System.Windows.Forms.ToolStripMenuItem();
        this.miFileOpen = new System.Windows.Forms.ToolStripMenuItem();
        this.miFileSave = new System.Windows.Forms.ToolStripMenuItem();
        this.miFileSaveAs = new System.Windows.Forms.ToolStripMenuItem();
        this.dlgOpenFile = new System.Windows.Forms.OpenFileDialog();
        this.mainMenu.SuspendLayout();
        this.SuspendLayout();
        // 
        // textBoxEdit
        // 
        this.textBoxEdit.AcceptsReturn = true;
        this.textBoxEdit.AcceptsTab = true;
        this.textBoxEdit.Dock = System.Windows.Forms.DockStyle.Fill;
        this.textBoxEdit.Location = new System.Drawing.Point(024);
        this.textBoxEdit.Multiline = true;
        this.textBoxEdit.Name = "textBoxEdit";
        this.textBoxEdit.ScrollBars = System.Windows.Forms.ScrollBars.Both;
        this.textBoxEdit.Size = new System.Drawing.Size(562219);
        this.textBoxEdit.TabIndex = 0;
        // 
        // mainMenu
        // 
        this.mainMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.miFile});
        this.mainMenu.Location = new System.Drawing.Point(00);
        this.mainMenu.Name = "mainMenu";
        this.mainMenu.Size = new System.Drawing.Size(56224);
        this.mainMenu.TabIndex = 1;
        this.mainMenu.Text = "menuStrip1";
        // 
        // miFile
        // 
        this.miFile.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.miFileNew,
            this.miFileOpen,
            this.miFileSave,
            this.miFileSaveAs});
        this.miFile.Name = "miFile";
        this.miFile.Text = "&File";
        // 
        // miFileNew
        // 
        this.miFileNew.Name = "miFileNew";
        this.miFileNew.Text = "&New";
        this.miFileNew.Click += new System.EventHandler(this.OnFileNew);
        // 
        // miFileOpen
        // 
        this.miFileOpen.Name = "miFileOpen";
        this.miFileOpen.Text = "&Open";
        this.miFileOpen.Click += new System.EventHandler(this.OnFileOpen);
        // 
        // miFileSave
        // 
        this.miFileSave.Name = "miFileSave";
        this.miFileSave.Text = "&Save";
        this.miFileSave.Click += new System.EventHandler(this.OnFileSave);
        // 
        // miFileSaveAs
        // 
        this.miFileSaveAs.Name = "miFileSaveAs";
        this.miFileSaveAs.Text = "Save &As";
        this.miFileSaveAs.Click += new System.EventHandler(this.OnFileSaveAs);
        // 
        // dlgOpenFile
        // 
        this.dlgOpenFile.Filter = "Text Documents (*.txt)|*.txt|Wrox Documents (*.wroxtext)|*.wroxtext|All Files|*.*" +
            "";
        this.dlgOpenFile.FilterIndex = 2;
        // 
        // SimpleEditorForm
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(562243);
        this.Controls.Add(this.textBoxEdit);
        this.Controls.Add(this.mainMenu);
        this.MainMenuStrip = this.mainMenu;
        this.Name = "SimpleEditorForm";
        this.Text = "Simple Editor";
        this.mainMenu.ResumeLayout(false);
        this.ResumeLayout(false);
        this.PerformLayout();

    }



    private System.Windows.Forms.TextBox textBoxEdit;
    private System.Windows.Forms.MenuStrip mainMenu;
    private System.Windows.Forms.ToolStripMenuItem miFile;
    private System.Windows.Forms.ToolStripMenuItem miFileNew;
    private System.Windows.Forms.ToolStripMenuItem miFileOpen;
    private System.Windows.Forms.ToolStripMenuItem miFileSave;
    private System.Windows.Forms.ToolStripMenuItem miFileSaveAs;
    private System.Windows.Forms.OpenFileDialog dlgOpenFile;

    [STAThread]
    static void Main(string[] args) {
        string filename = null;
        if (args.Length != 0)
            filename = args[0];

        Application.EnableVisualStyles();
        Application.Run(new SimpleEditorForm(filename));
    }

}

 
Related examples in the same category
1. Add ScrollBars to TextBox
2. new TextBox(), Localtion, Name, TabIndex, Text
3. TextBox locationTextBox location
4. Keyboard event and TextBox
5. Get value from TextBox
6. Text Changed eventText Changed event
7. A simple text editorA simple text editor
8. Convert TextBox input to double valueConvert TextBox input to double value
9. All cap text textboxAll cap text textbox
10. Data CheckerData Checker
11. User EventsUser Events
12. TextBox and button on formTextBox and button on form
13. TextBox and ListBoxTextBox and ListBox
14. Label, TextBox and ButtonLabel, TextBox and Button
15. TextBox DemoTextBox Demo
ww__w___.___j___a_v__a__2___s__.__co_m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.