C # Discovery Tour 14th lecture on dynamically compiled vb.net script engine (bottom)

Source: Internet
Author: User
Tags filter bool

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 = "";


}

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.