Use C # To compile a simple notebook,
Using System; using System. collections. generic; using System. componentModel; using System. data; using System. drawing; using System. linq; using System. text; using System. threading. tasks; using System. windows. forms; namespace Notepad {public partial class frmNotepad: form {//************************************ * **********************************/* Boolean variable B used to determine whether a file is created or opened from a disk. true indicates that the file is opened from the disk, false indicates that the file is created. The default value is false. */Bool B = false;/* Boolean variable s is used to determine whether the file is saved. true indicates that the file has been saved. false indicates that the file has not been saved. The default value is true */bool s = true; //************************************** * ******************************** public frmNotepad () {InitializeComponent (); richTextBox1.Text = "";} //************************************** * ********************************** // multi-format text box textChanged Event code //********************************** **************************** * ********** Private void richtextbox=textchanged (object sender, EventArgs e) {// after the text box is modified, set s to false, the file is not saved. s = false ;} //************************************** * ********************************** // [file] click the code of each menu item //******************************* **************************************** **//************************************ *************************************//【 new menu code //****************** **************************************** * ************** Private void to create NToolStripMenuItem_Click (object sender, eventArgs e) {// checks whether the current file is opened from the disk, or if (B = true | richTextBox1.Text. trim ()! = "") {// If the file is not saved if (s = false) {string result; result = MessageBox. Show ("the file is not saved yet. Are you sure you want to save it? "," Save file ", MessageBoxButtons. yesNoCancel ). toString (); switch (result) {case "Yes": // if the file is open from the disk if (B = true) {// Save the richTextBox1.SaveFile (sdlgNotepad. fileName);} else if (sdlgNotepad. showDialog () = DialogResult. OK) {richTextBox1.SaveFile (sdlgNotepad. fileName) ;}s = true; richTextBox1.Text = ""; break; case "No": B = false; richTextBox1.Text = ""; break ;}}}} //************************** **************************************** * ******/[Save] The Menu code //************************ **************************************** * ******* private void to save SToolStripMenuItem_Click (object sender, eventArgs e) {// if the file is opened from the disk and the content is modified if (B = true & richTextBox1.Modified = true) {richTextBox1.SaveFile (odlgNotepad. fileName); s = true;} else if (B = false & richTextBox1.Text. trim ()! = "" & SdlgNotepad. showDialog () = DialogResult. OK) {// Save the richTextBox1.SaveFile (sdlgNotepad. fileName); s = true; B = true; odlgNotepad. fileName = sdlgNotepad. fileName ;}} //************************************** * ***********************************/[open] menu code //************************************ * *********************************** private void to open OToolStripMenuItem_Click (object sender, eventAr Gs e) {// determines whether the current file is opened from the disk, or whether the file is not empty when it is created, and the file is not saved. try {if (B = true | richTextBox1.Text. trim ()! = "") {If (s = false) {string result; result = MessageBox. Show ("the file has not been saved. Are you sure you want to save it? "," Save file ", MessageBoxButtons. yesNoCancel ). toString (); switch (result) {case "Yes": // if the file is open from the disk if (B = true) {// Save the richTextBox1.SaveFile (sdlgNotepad. fileName);} else if (sdlgNotepad. showDialog () = DialogResult. OK) {richTextBox1.SaveFile (sdlgNotepad. fileName) ;}s = true; richTextBox1.Text = ""; break; case "No": B = false; richTextBox1.Text = ""; break ;}} odlgNotepad. restoreDir Ecloud = true; if (odlgNotepad. ShowDialog () = DialogResult. OK) & odlgNotepad. FileName! = "") {// Open the file richTextBox1.LoadFile (odlgNotepad. fileName); B = true;} s = true;} catch (Exception ex) {}}//*********************************** **************************************// [Save As] menu code //********************************* **************************************** private void Save As AToolStripMenuItem_Click (object sender, eventArgs e) {if (sdlgNotepad. showDialog () = DialogResult. OK) {richTextBox1.SaveFile (sdlgNotepad. fileName); s = true ;}} //**************************************] menu code //************************************ * *********************************** private void exit XToolStripMenuItem_Click (object sender, eventArgs e) {// end the program running Application. exit ();} //************************************** * ********************************** // [edit] click the code of each menu item //******************************* **************************************** ** // [undo] menu code private void undo UToolStripMenuItem_Click (object sender, eventArgs e) {// revoke richTextBox1.Undo ();} // [copy] menu code private void copy CToolStripMenuItem_Click (object sender, EventArgs e) {// copy richTextBox1.Copy ();} // [CUT] menu code private void cut TToolStripMenuItem_Click (object sender, EventArgs e) {// cut richTextBox1.Cut ();} // [paste] menu code private void paste PToolStripMenuItem_Click (object sender, EventArgs e) {// paste richTextBox1.Paste ();} // [select all] menu code private void select all AToolStripMenuItem_Click (object sender, EventArgs e) {// select all richTextBox1.SelectAll ();} //************************************** * ********************************** // [format] menu code //************************************ * *********************************** private void Tool TToolStripMenuItem_Click (object sender, eventArgs e) {}// [wrap automatically] menu code private void custom CToolStripMenuItem_Click (object sender, EventArgs e) {if (custom CToolStripMenuItem. checked = false) {// select the custom CToolStripMenuItem for automatic line feed. checked = true; // set to automatically wrap richTextBox1.WordWrap = true;} else {// custom CToolStripMenuItem is not selected. checked = false; // set to do not automatically wrap richTextBox1.WordWrap = false;} // [font] menu code private void option OToolStripMenuItem_Click (object sender, EventArgs e) {fdlgNotepad. showColor = true; if (fdlgNotepad. showDialog () = DialogResult. OK) {richTextBox1.SelectionColor = fdlgNotepad. color; richTextBox1.SelectionFont = fdlgNotepad. font ;}} //************************************** *********************************** // [help] menu code //************************************ *************************************//【 about menu code private void about AToolStripMenuItem_Click (object sender, eventArgs e) {MessageBox. show ("wky writing", "about \" Notepad \ "", MessageBoxButtons. OK );} //************************************** * ********************************** // Timer control tick Event code //*********************************** * ************************************ private void tmrNotepad_Tick (object sender, eventArgs e) {// obtain the current System time and display it in the status bar tssLbl2.Text = System. dateTime. now. toString ();} private void paste PToolStripButton_Click (object sender, EventArgs e) {richTextBox1.Paste ();}}}