SoFunction
Updated on 2025-03-07

C# Write a simple notepad function

This article has shared the specific code for writing notepad in C# for your reference. The specific content is as follows

using System;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;


namespace Notepad
{
 public partial class frmNotepad : Form
 { 
  //************************************************************
   /*Boolean variable b is used to determine whether the file is newly created or opened from disk. True means opening from disk. False means the file is newly created. The default value is false*/
  bool b = false;
  /*Boolean variable s is used to determine whether the file is saved. True means it has been saved. False means it has not been saved. The default value is true*/
  bool s = true;
  //***********************************

  public frmNotepad()
  {
   InitializeComponent();
    = "";
  }

  //*********************************************** 
  // TextChanged event code for multi-format text boxes  //************************************************ 
  private void richTextBox1_TextChanged(object sender, EventArgs e)
  {
   //After the text box is modified, set s to false, indicating that the file has not been saved   s = false;
  }


  //***************************************** 
  // [File] Click code for each menu item in the menu  //******************************************* 
  //*****************************************
  // 【New】Menu Code  //*********************************************
  private void NewNToolStripMenuItem_Click(object sender, EventArgs e)
  {
   //Determine whether the current file is opened from disk, or the document is not empty when created, and the file is not saved   if(b == true || () != "")
   {
    //If the file is not saved    if(s == false)
    {
     string result;
     result = ("The file has not been saved yet, is it saved?", "Save File", ).ToString();
     switch(result)
     {
      case"Yes":
       //If the file is opened from disk       if(b == true)
       {
        //Save the file by the path to open the file        ();
       }else if(()==)
       {
        ();
       }
       s = true;
        = "";
       break;
      case"No":
       b = false;
        = "";
       break;
     }
    }
   }
  }

  //******************************************* 
  // 【Save】Menu Code  //********************************************
  private void saveSToolStripMenuItem_Click(object sender, EventArgs e)
  {
   //If the file is opened from disk and the contents are modified   if(b == true &&  == true)
   {
    ();
    s = true;
   }
   else if(b == false && () != "" &&() == )
   {
    //Save the file    ();
    s = true;
    b = true;
     = ;
   }
  }

  //********************************************** 
  // 【Open】Menu Code  //************************************************
  private void OpenOToolStripMenuItem_Click(object sender, EventArgs e)
  {
    //Determine whether the current file is opened from disk, or the document is not empty when created, and the file is not saved   try
   {
    if (b == true || () != "")
    {
     if (s == false)
     {
      string result;
      result = ("The file has not been saved yet, is it saved?", "Save File", ).ToString();
      switch (result)
      {
       case "Yes":
        //If the file is opened from disk        if (b == true)
        {
         //Save the file by the path to open the file         ();
        }
        else if (() == )
        {
         ();
        }
        s = true;
         = "";
        break;
       case "No":
        b = false;
         = "";
        break;
      }
     }
    }
     = true;
    if ((() == ) &&  != "")
    {
     //Open the file     ();
     b = true;
    }
    s = true;
   }
   catch(Exception ex)
   {
     
   }

  }

  //************************************ 
  // 【Save As】Menu Code  //***************************************** 
  private void Save asAToolStripMenuItem_Click(object sender, EventArgs e)
  {
   if(() == )
   {
    ();
    s = true;
   }
  }

  //*************************************** 
  // 【Exit】Menu Code  //******************************************
  private void quitXToolStripMenuItem_Click(object sender, EventArgs e)
  {
   //End the program running   ();
  }

  //************************************ 
  // 【Edit】Click code for each menu item in the menu  //********************************************* 
  // 【Undo】Menu Code  private void UndoUToolStripMenuItem_Click(object sender, EventArgs e)
  {
   //Revoke the operation   ();
  }

  // 【Copy】Menu Code  private void copyCToolStripMenuItem_Click(object sender, EventArgs e)
  {
   //copy   ();
  }

  // 【Cut】Menu Code  private void CutTToolStripMenuItem_Click(object sender, EventArgs e)
  {
   //Cut   ();
  }

  // 【Paste】Menu Code  private void PastePToolStripMenuItem_Click(object sender, EventArgs e)
  {
   //Paste   ();
  }

  // 【Select All】Menu Code  private void Select allAToolStripMenuItem_Click(object sender, EventArgs e)
  {
   //Select all   ();
  }

  //************************************* 
  // 【Format】Menu Code  //*************************************** 
  private void toolTToolStripMenuItem_Click(object sender, EventArgs e)
  {

  }

  // 【Automatic line wrap】Menu code  private void CustomizeCToolStripMenuItem_Click(object sender, EventArgs e)
  {
   if(Customize == false)
   {
    //Select Automatic Winding    Customize = true;
    //Set to automatic line wrap     = true;
   }
   else
   {
    //Unselected automatic line wrap    Customize = false;
    //Set to not automatically wrap     = false;
   }
  }

  // 【Font】Menu Code  private void OptionsOToolStripMenuItem_Click(object sender, EventArgs e)
  {
    = true;
   if(() == )
   {
     = ;
     = ;
   }
  }

  //************************************ 
  // 【Help】Menu Code  //************************************
  // 【About】Menu Code  private void aboutAToolStripMenuItem_Click(object sender, EventArgs e)
  {
   ("wky written", "about\"Notebook\"", );
  }

  //*************************************** 
  // Tick event code of timer control  //************************************
  private void tmrNotepad_Tick(object sender, EventArgs e)
  {
   //Get the current time of the system and display it in the status bar    = ();
  }

  private void PastePToolStripButton_Click(object sender, EventArgs e)
  {
   ();
  }

  

 }
}

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.