Simple Notepad program Menu Design

Source: Internet
Author: User

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!

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.