A simple text editor : TextBox « GUI Windows Form « C# / C Sharp

Home
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.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » GUI Windows Form » TextBoxScreenshots 
A simple text editor
A simple text editor

using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

public class MenuDialog : Form {
  TextBox text = new TextBox();

  public MenuDialog() {
    Size = new Size(500,200);

    text.Size = new Size(490,190);
    text.Multiline = true;
    text.ScrollBars = ScrollBars.Both;
    text.WordWrap = false;
    text.Location = new Point(5,5);

    MenuItem fileMenu = new MenuItem("File");
    MenuItem open = new MenuItem("Open");
    open.Shortcut = Shortcut.CtrlO;
    MenuItem save = new MenuItem("Save");
    save.Shortcut = Shortcut.CtrlS;
    fileMenu.MenuItems.Add(open);
    fileMenu.MenuItems.Add(save);

    MenuItem formatMenu = new MenuItem("Format");
    MenuItem font = new MenuItem("Font");
    font.Shortcut = Shortcut.CtrlF;
    formatMenu.MenuItems.Add(font);
     
    MainMenu bar = new MainMenu();
    Menu = bar;
    bar.MenuItems.Add(fileMenu);
    bar.MenuItems.Add(formatMenu);

    Controls.Add(text);

    open.Click += new EventHandler(Open_Click);
    save.Click += new EventHandler(Save_Click);
    font.Click += new EventHandler(Font_Click)
  }
  
  protected void Open_Click(Object sender, EventArgs e) {
    OpenFileDialog o = new OpenFileDialog();
    if(o.ShowDialog() == DialogResult.OK) {
      Stream file = o.OpenFile();
      StreamReader reader = new StreamReader(file);
      char[] data = new char[file.Length];
      reader.ReadBlock(data,0,(int)file.Length);
      text.Text = new String(data);  
      reader.Close();
    }
  }

  protected void Save_Click(Object sender, EventArgs e) {
    SaveFileDialog s = new SaveFileDialog();
    if(s.ShowDialog() == DialogResult.OK) {
      StreamWriter writer = new StreamWriter(s.OpenFile());
      writer.Write(text.Text);
      writer.Close();
    }
  }
  protected void Font_Click(Object sender, EventArgs e) {
    FontDialog f = new FontDialog();
    if(f.ShowDialog() == DialogResult.OK
      text.Font = f.Font;
  }

  public static void Main() {
    Application.Run(new MenuDialog());
  }
}

           
       
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.Convert TextBox input to double valueConvert TextBox input to double value
8.All cap text textboxAll cap text textbox
9.Data CheckerData Checker
10.User EventsUser Events
11.TextBox and button on formTextBox and button on form
12.TextBox and ListBoxTextBox and ListBox
13.Label, TextBox and ButtonLabel, TextBox and Button
14.TextBox DemoTextBox Demo
15.Simple Editor based on TextBox
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.