NotePad App in C#
-
Upload
zohair-ahmed -
Category
Documents
-
view
61 -
download
2
description
Transcript of NotePad App in C#
-
Open a new C# project by opening Microsoft Visual C#, and then go to
File>New>Windows Form Application
Name the project Notepad or whatever you want.
Add the following items. (Menu Strip, openFileDialog, saveFileDialog, Rich Text Box)
-
Now right click on a blank part of the menu strip, and press "Insert Standard Items"
You should have a bunch of basic functions by now, but its not that easy , they all dont have code.
But start off by deleting "Tools" and "Help".
Now in your form editor click on the "File" button, then double click on "New", which should bring you
to the code editor, then write the code
After That Add Open File and Save File Dialog Filter
This filter open only txt format file
Also save only textiles only
See Given Below Screen
-
After That Double Click Menu you want to add functionality
For Example DoubleClick on New then Event Fire Below
Then Display this Screen
Double Click
on New
-
Must Include this using System.IO;
In Above Event Write This Code
richTextBox1.Clear();
After That Call Events by double clicking on menu
Add code Open New Notepad File
private void openToolStripMenuItem_Click(object sender, EventArgs e) { openFileDialog1.ShowDialog(); StreamReader rd = new StreamReader(openFileDialog1.FileName); richTextBox1.Text= rd.ReadToEnd(); rd.Close(); }
Save Existing item Using Dynamic Location on Local Drives
private void saveToolStripMenuItem_Click(object sender, EventArgs e) { saveFileDialog1.ShowDialog(); StreamWriter rd = new StreamWriter(saveFileDialog1.FileName); rd.WriteLine(richTextBox1.Text); rd.Close(); }
"Print"'s code is
//Declare prntDoc as a new PrintDocument System.Drawing.Printing.PrintDocument prntDoc = new System.Drawing.Printing.PrintDocument();
-
"Print Preview" is
//Declare preview as a new PrintPreviewDialog
PrintPreviewDialog preview = new PrintPreviewDialog();
//Declare prntDoc_PrintPage as a new EventHandler for prntDoc's Print Page
prntDoc.PrintPage += new
System.Drawing.Printing.PrintPageEventHandler(prntDoc_PrintPage);
//Set the PrintPreview's Document equal to prntDoc
preview.Document = prntDoc;
//Show the PrintPreview Dialog
if (preview.ShowDialog(this) == DialogResult.OK)
{
//Generate the PrintPreview
prntDoc.Print();
}
"Exit"'s code is
Application.Exit();
Move on to "Undo"'s code, add
richTextBox.Undo();
For "Redo"'s code its
richTextBox.Undo();
-
Add this to "Cut"'s code
richTextBox.Cut();
For "Copy" add
richTextBox.Copy();
"Paste"'s code is
richTextBox.Paste();
For "Select All" its
richTextBox.SelectAll();
For Font Change ,Bold etc
richTextBox1.SelectionFont = new Font("Arial", 8, FontStyle.Bold);