C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » .NET Framework »

How to create a Notepad application


Posted Date: 19 Feb 2004    Resource Type: Articles    Category: .NET Framework
Author: amitabh doctorMember Level: Bronze    
Rating: 1 out of 5Points: 5



Creating a Notepad application in C#

The advantage of C# is that you can create various examples using the technology that it provides. One such example is that like Notepad. A notepad is basic application but it is a start towards developing a application which can be called state of the art. This notepad application can be changed as per your requirements besides various other features can be added to create the application even more powerful.

Notepad.cs

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;

namespace csnotepad
{
///
/// Summary description for Form1.
///

public class notepad : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.MenuItem menuItem6;
private System.Windows.Forms.MenuItem menuItem7;
private System.Windows.Forms.MenuItem menuItem8;
private System.Windows.Forms.MenuItem menuItem9;
private System.Windows.Forms.MenuItem menuItem10;
private System.Windows.Forms.MenuItem menuItem11;
private System.Windows.Forms.MenuItem menuItem12;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.MenuItem menuItem14;
private System.Windows.Forms.SaveFileDialog saveFileDialog1;
private System.Windows.Forms.MenuItem menuItem13;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.MenuItem menuItem15;
private System.Windows.Forms.MenuItem menuItem16;
///
/// Required designer variable.
///

private System.ComponentModel.Container components = null;

public notepad()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

///
/// Clean up any resources being used.
///

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem13 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuItem14 = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
this.menuItem7 = new System.Windows.Forms.MenuItem();
this.menuItem8 = new System.Windows.Forms.MenuItem();
this.menuItem9 = new System.Windows.Forms.MenuItem();
this.menuItem10 = new System.Windows.Forms.MenuItem();
this.menuItem11 = new System.Windows.Forms.MenuItem();
this.menuItem12 = new System.Windows.Forms.MenuItem();
this.menuItem15 = new System.Windows.Forms.MenuItem();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.textBox1 = new System.Windows.Forms.TextBox();
this.menuItem16 = new System.Windows.Forms.MenuItem();
this.SuspendLayout();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.menuItem6,
this.menuItem11,
this.menuItem15});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2,
this.menuItem3,
this.menuItem13,
this.menuItem4,
this.menuItem14,
this.menuItem5});
this.menuItem1.Text = "File";
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.Text = "&New";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// menuItem3
//
this.menuItem3.Index = 1;
this.menuItem3.Text = "&Open";
this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
//
// menuItem13
//
this.menuItem13.Index = 2;
this.menuItem13.Text = "-";
//
// menuItem4
//
this.menuItem4.Index = 3;
this.menuItem4.Text = "&Save";
this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
//
// menuItem14
//
this.menuItem14.Index = 4;
this.menuItem14.Text = "-";
//
// menuItem5
//
this.menuItem5.Index = 5;
this.menuItem5.Text = "Exit";
this.menuItem5.Click += new System.EventHandler(this.menuItem5_Click_1);
//
// menuItem6
//
this.menuItem6.Index = 1;
this.menuItem6.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem7,
this.menuItem8,
this.menuItem9,
this.menuItem10});
this.menuItem6.Text = "Edit";
//
// menuItem7
//
this.menuItem7.Index = 0;
this.menuItem7.Text = "&Cut";
this.menuItem7.Click += new System.EventHandler(this.menuItem7_Click);
//
// menuItem8
//
this.menuItem8.Index = 1;
this.menuItem8.Text = "&Copy";
this.menuItem8.Click += new System.EventHandler(this.menuItem8_Click);
//
// menuItem9
//
this.menuItem9.Index = 2;
this.menuItem9.Text = "Paste";
this.menuItem9.Click += new System.EventHandler(this.menuItem9_Click);
//
// menuItem10
//
this.menuItem10.Index = 3;
this.menuItem10.Text = "&Select All";
this.menuItem10.Click += new System.EventHandler(this.menuItem10_Click);
//
// menuItem11
//
this.menuItem11.Index = 2;
this.menuItem11.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem12,
this.menuItem16});
this.menuItem11.Text = "Help";
//
// menuItem12
//
this.menuItem12.Index = 0;
this.menuItem12.Text = "About";
this.menuItem12.Click += new System.EventHandler(this.menuItem12_Click);
//
// menuItem15
//
this.menuItem15.Index = 3;
this.menuItem15.Text = "";
//
// saveFileDialog1
//
this.saveFileDialog1.FileName = "doc1";
//
// textBox1
//
this.textBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.textBox1.Size = new System.Drawing.Size(544, 321);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged_1);
//
// menuItem16
//
this.menuItem16.Index = 1;
this.menuItem16.Text = "General";
this.menuItem16.Click += new System.EventHandler(this.menuItem16_Click);
//
// notepad
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(544, 321);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textBox1});
this.ImeMode = System.Windows.Forms.ImeMode.Off;
this.Menu = this.mainMenu1;
this.Name = "notepad";
this.Text = "C# Notepad";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);

}
#endregion

///
/// The main entry point for the application.
///

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

private void Form1_Load(object sender, System.EventArgs e)
{

}

private void menuItem3_Click(object sender, System.EventArgs e)
{
// for opening file
openFileDialog1.ShowDialog();
StreamReader sr = new StreamReader(openFileDialog1.FileName);
textBox1.Text = sr.ReadToEnd();
sr.Close();

}

private void menuItem7_Click(object sender, System.EventArgs e)
{
Clipboard.SetDataObject(textBox1.SelectedText);
textBox1.SelectedText="";

}

private void menuItem9_Click(object sender, System.EventArgs e)
{
textBox1.Paste();
}

private void textBox1_TextChanged(object sender, System.EventArgs e)
{

}

private void menuItem12_Click(object sender, System.EventArgs e)
{
Form2 helpnew = new Form2();
helpnew.Show();

}

private void textBox1_TextChanged_1(object sender, System.EventArgs e)
{

}

private void menuItem5_Click(object sender, System.EventArgs e)
{

}

private void menuItem5_Click_1(object sender, System.EventArgs e)
{
Dispose(true);
}

private void menuItem8_Click(object sender, System.EventArgs e)
{
textBox1.Copy();
}

private void menuItem10_Click(object sender, System.EventArgs e)
{
textBox1.SelectAll();

}

private void menuItem2_Click(object sender, System.EventArgs e)
{
textBox1.Clear();

}

private void menuItem4_Click(object sender, System.EventArgs e)
{
// for file save
saveFileDialog1.FileName = "*.txt";
//saveFileDialog1.FilterIndex ="*.txt";
saveFileDialog1.ShowDialog();
//MessageBox.Show (saveFileDialog1.FileName);
StreamWriter sw = new StreamWriter(saveFileDialog1.FileName);
sw.Write (textBox1.Text);
sw.Close();
}

private void menuItem16_Click(object sender, System.EventArgs e)
{
Form3 gen = new Form3 ();
gen.Show();



}


}
}





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Passing Parameters
Previous Resource: HOW TO: Getting the members of enumeration
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use