Click here to Skip to main content
14,028,254 members
Click here to Skip to main content
Add your own
alternative version


23 bookmarked
Posted 6 Jun 2004

Notepad Application in C#

, 6 Jun 2004
Rate this:
Please Sign up or sign in to vote.
An article on C# describing a notepad application


Beginners often find some problems in understanding the fundamental controls of any new language. This article is my first attempt to make a few controls and application development in the C# environment a little more familiar.

As I am new to writing articles kindly post me comments on any mistakes committed during this presentation and ignore any grammatical/spelling mistakes as I am not to be blamed for that. (a bad try to escape)

I have used the tools OpenFileDialog, SaveFileDialog, PageSetupDialog, PrintDialog, PrintPreviewDialog, FontDialog, etc; for the functions of opening a file, saving a file, page setup, printing the document, print preview of the document and font selection. The client area is a multi line edit box with vertical scroll provided by default.

Using the code

The root namespace which is used very often for describing and including various controls is System.Windows.Forms.

I have declared a variable "dirty" of the Boolean (bool keyword) type. This identifies any change in the client area by any user event. This variable is by default set to false and is made true only when there is a change occurring in the editable multi line text box which is identified in the function

private void txt_TextChanged(object sender, System.EventArgs e)

The code for opening a file using OpenFileDialog is given below. ofd is an object of the OpenFileDialog class. This function makes use of the StreamReader class object to read the text input.

private void mopen_Click(object sender, System.EventArgs e)
  ofd.Multiselect = false;
  ofd.Filter = "Text Files|*.txt";
  if (File.Exists(ofd.FileName))
    fname = ofd.FileName;
    StreamReader sr = new StreamReader(fname);
    dirty = false;

The code for saving a file is given below. sfd is an object of the SaveFileDialog class. This function makes use of the StreamWriter class object to read the contents and write to the file to be saved.


StreamWriter sw = new 
" passes the file name as a variable to the constructor of StreamWriter class to initialize the file to be written using the StreamWriter object.

private void savedata()
  if (fname == "")
    sfd.Filter = "Text Files|*.txt";
    DialogResult res = sfd.ShowDialog();
    if (res == DialogResult.Cancel)
    fname = sfd.FileName;
  StreamWriter sw = new StreamWriter(fname);
  dirty = false;

Points of Interest

I don't say that this is a very good idea, but this is the demonstration, and this may be enhanced. Modifications/good ideas are welcomed with regards.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Abhishek M
Web Developer
India India
No Biography provided

You may also be interested in...


Comments and Discussions

Questionnotepad code in c# Pin
prasad60621-Jul-15 20:30
memberprasad60621-Jul-15 20:30 
GeneralReadToEnd() Pin
vince_204816-Apr-09 4:01
membervince_204816-Apr-09 4:01 
Generalproblem Pin
James_Zhang16-Dec-08 14:11
memberJames_Zhang16-Dec-08 14:11 
GeneralPrint does not work Pin
jpma5-Aug-08 10:16
memberjpma5-Aug-08 10:16 
Generala more codes Pin
tinred16-Aug-06 23:11
membertinred16-Aug-06 23:11 problem Pin
sidda15-Jan-06 7:29
membersidda15-Jan-06 7:29 
GeneralRe: problem Pin
bindukrishna2-Nov-07 20:35
memberbindukrishna2-Nov-07 20:35 
GeneralRe: problem Pin
prasad60621-Jul-15 20:53
memberprasad60621-Jul-15 20:53 
GeneralCopy Paste Problem Pin
godfathers17-Mar-05 23:00
membergodfathers17-Mar-05 23:00 
Generaltry/finally Pin
Marek_J7-Jun-04 6:44
memberMarek_J7-Jun-04 6:44 
QuestionWho are you? Pin
Uwe Keim6-Jun-04 23:55
sitebuilderUwe Keim6-Jun-04 23:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02 | 2.8.190419.4 | Last Updated 7 Jun 2004
Article Copyright 2004 by Abhishek M
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid