The main form also defines functions such as function_new,function_open,function_save and so on to implement new, open, and save files for the document. And the buttons on the toolbar call these function functions. The code that defines these functional functions is as follows
///<summary>
///Execute New Document
///</summary>
public bool Function_new ()
{
if (Querysave ())
{
txteditor.text = "";
txteditor.modified = false;
strFileName = null;
return true;
}
return false;
}
///<summary>
///Execute Open File Operation
///</summary>
public bool Function_open ()
{
if (querysave () = False)
{
return false;
}
using (OpenFileDialog dlg = new OpenFileDialog ())
{
Dlg. Filter = "text file (*.txt) |*.txt| all Files |*.*";
dlg. Checkpathexists = true;
if (dlg. ShowDialog (This) = = DialogResult.OK)
{
System.IO.StreamReader reader = new System.IO.StreamReader (
dlg. FileName, System.Text.Encoding.GetEncoding ("gb2312"));
txteditor.text = reader. ReadToEnd ();
Reader. Close ();
strFileName = dlg. FileName;
txteditor.modified = false;
return true;
}
}
return false;
}
///<summary>
///Perform a save document operation
///</summary>
///<returns> Operation Success </returns>
public bool Function_save ()
{
if (strFileName = null)
{
using (SaveFileDialog dlg = new SaveFileDialog ())
{
dlg. Filter = "text file (*.txt) |*.txt| all Files |*.*";
dlg. Checkpathexists = true;
dlg. Overwriteprompt = true;
if (dlg. ShowDialog (This) = = DialogResult.OK)
{
strFileName = dlg. FileName;
}
Else
{
return false;
}
}
}
System.IO.StreamWriter writer = new System.IO.StreamWriter (
strFileName, False, System.Text.Encoding.GetEncoding ("gb2312"));
writer. Write (This.txtEditor.Text);
writer. Close ();
This.txtEditor.Modified = false;
return true;
}
///<summary>
///Execute Save As Operation
///</summary>
public bool Function_saveas ()
{
using (SaveFileDialog dlg = new SaveFileDialog ())
{
dlg. Filter = "text file (*.txt) |*.txt| all Files |*.*";
dlg. Checkpathexists = true;
dlg. Overwriteprompt = true;
if (dlg. ShowDialog (This) = = DialogResult.OK)
{
strFileName = dlg. FileName;
System.IO.StreamWriter writer = new System.IO.StreamWriter (
strFileName, False, System.Text.Encoding.GetEncoding ("gb2312"));
writer. Write (This.txtEditor.Text);
writer. Close ();
This.txtEditor.Modified = false;
return true;
}
}
return false;
}
///<summary>
///Perform a select operation
///</summary>
public void Function_selectall ()
{
Txteditor.selectall ();
}
///<summary>
///perform a cut operation
///</summary>
public void Function_cut ()
{
txteditor.cut ();
}
///<summary>
///Perform a copy operation
///</summary>
public void function_copy ()
{
txteditor.copy ();
}
///<summary>
///perform sticky operation
///</summary>
public void Function_paste ()
{
Txteditor.paste ();
}
///<summary>
///Perform the delete operation
///</summary>
public void Function_delete ()
{
txteditor.selectedtext = "";
}