Code in form1.cs!
Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. LINQ;
Using system. text;
Using system. Windows. forms;
Namespace notepadapp
{
Public partial class form1: Form
{
Public form1 ()
{
Initializecomponent ();
}
Private void create ntoolstripmenuitem_click (Object sender, eventargs E)
{
Noteform note = new noteform ();
Note. mdiparent = this;
Note. Show ();
}
Private void exit xtoolstripmenuitem_click (Object sender, eventargs E)
{
This. Close ();
}
Private void about atoolstripmenuitem_click (Object sender, eventargs E)
{
MessageBox. Show ("simple Notepad program ");
}
Private void open otoolstripmenuitem_click (Object sender, eventargs E)
{
String fileurl = "";
Openfiledialog openfiledialog1 = new openfiledialog ();
Openfiledialog1.initialdirectory = "C ://";
Openfiledialog1.filter = "TXT files (*. txt) | *. txt | all files (*. *) | *.*";
Openfiledialog1.restoredirectory = true;
If (openfiledialog1.showdialog () = dialogresult. OK)
{
Fileurl = openfiledialog1.filename;
}
Noteform note = new noteform ();
Note. mdiparent = this;
Note. Show ();
Note. openfile (fileurl );
}
Private void save stoolstripmenuitem_click (Object sender, eventargs E)
{
If (this. activemdichild! = NULL)
{
Noteform activeform = (noteform) This. activemdichild;
Activeform. SaveFile ();
}
}
Private void undo utoolstripmenuitem_click (Object sender, eventargs E)
{
If (this. activemdichild! = NULL)
{
Noteform activeform = (noteform) This. activemdichild;
Activeform. frmundo ();
}
}
Private void repeat rtoolstripmenuitem_click (Object sender, eventargs E)
{
If (this. activemdichild! = NULL)
{
Noteform activeform = (noteform) This. activemdichild;
Activeform. frmredo ();
}
}
Private void cut ttoolstripmenuitem_click (Object sender, eventargs E)
{
If (this. activemdichild! = NULL)
{
Noteform activeform = (noteform) This. activemdichild;
Activeform. frmcut ();
}
}
Private void copy ctoolstripmenuitem_click (Object sender, eventargs E)
{
If (this. activemdichild! = NULL)
{
Noteform activeform = (noteform) This. activemdichild;
Activeform. frmcopy ();
}
}
Private void paste ptoolstripmenuitem_click (Object sender, eventargs E)
{
If (this. activemdichild! = NULL)
{
Noteform activeform = (noteform) This. activemdichild;
Activeform. frmpaste ();
}
}
For private void, select atoolstripmenuitem_click (Object sender, eventargs E)
{
If (this. activemdichild! = NULL)
{
Noteform activeform = (noteform) This. activemdichild;
Activeform. frmselectall ();
}
}
}
}
Add another window!
Equivalent to the client!
Name it notepadapp. CS
The code is
Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. LINQ;
Using system. text;
Using system. Windows. forms;
Using system. IO;
Namespace notepadapp
{
Public partial class noteform: Form
{
String filename = "";
Public noteform ()
{
Initializecomponent ();
This. windowstate = formwindowstate. maximized;
}
Public void openfile (string fileurl)
{
Filename = fileurl;
Stringbuilder sb = new stringbuilder ();
Using (streamreader sr = file. opentext (fileurl ))
{
String input = "";
While (input = Sr. Readline ())! = NULL)
{
SB. append (input );
}
Sr. Close ();
}
This. richtextbox1.text = sb. tostring ();
}
Public void SaveFile ()
{
If (filename = "")
{
If (this. savefiledialog1.showdialog () = dialogresult. OK)
{
Filename = savefiledialog1.filename;
}
}
Using (streamwriter Sw = new streamwriter (filename ))
{
Sw. Write (this. richtextbox1.text );
}
}
Public void frmcopy ()
{
This. richtextbox1.copy ();
}
Public void frmpaste ()
{
This. richtextbox1.paste ();
}
Public void frmcut ()
{
This. richtextbox1.cut ();
}
Public void frmselectall ()
{
This. richtextbox1.selectall ();
}
Public void frmundo ()
{
This. richtextbox1.undo ();
}
Public void frmredo ()
{
This. richtextbox1.redo ();
}
}
}
Finally, it is worth mentioning that you can quickly create a menu item and drag menustrip to the window in the toolbar, and then select the key in the upper right corner of menustrip.
A standard menu set! Delete unnecessary items by editing items!