C # notepad V2.0

Source: Internet
Author: User

On the basis of notepad V1.0, added the cut, assignment, paste, and delete functions in editing, and made some changes to the processing before the program is closed.

 

Newly Added code:

// Operation of the system clipboard
Private void copy toolstripmenuitem_click (Object sender, eventargs E)
{
If (this. textbox1.selectedtext! = "")
{
Clipboard. setdataobject (this. textbox1.selectedtext );
}
Else
MessageBox. Show ("No selected text! ");
}

Private void pasting toolstripmenuitem_click (Object sender, eventargs E)
{
Idataobject idata = clipboard. getdataobject ();

// Check whether the data is in the available format, that is, the text format.
If (idata. getdatapresent (dataformats. Text ))
{
If (this. textbox1.selectedtext! = "")
{
Textbox1.selectedtext = (string) idata. getdata (dataformats. Text );
}
Else
{
Textbox1.text + = (string) idata. getdata (dataformats. Text );
}
}
Else
{
MessageBox. Show ("No data is received from the clipboard! ");
}
}

Private void Delete toolstripmenuitem_click (Object sender, eventargs E)
{
This. textbox1.selectedtext = "";
}

Private void cut xtoolstripmenuitem_click (Object sender, eventargs E)
{
If (this. textbox1.selectedtext! = "")
{
Clipboard. setdataobject (this. textbox1.selectedtext );
This. textbox1.selectedtext = "";
}
Else
MessageBox. Show ("No selected text! ");

}

 

Modified code:

// Check whether the file is saved before closing
Private void mynotepad_formclosing (Object sender, formclosingeventargs E)
{
If (this. textbox1.text! = "")
{
If (! File. exists (this. Text ))
{
Dialogresult d = MessageBox. Show (the text of "file" + this. Text + @ "has changed.
Do you want to save the file? "," Mynotepad ", messageboxbuttons. yesnocancel, messageboxicon. Information, messageboxdefaultbutton. button1, messageboxoptions. defaulttoptoponly );
Switch (d)
{
Case dialogresult. Yes:
Using (savefiledialog savedig = new savefiledialog ())
{
Savedig. Filter = @ "Text Document (*. txt) | *. txt ";
Savedig. filename = "*. txt ";
If (savedig. showdialog () = dialogresult. OK)
{
Streamwriter Sw = new streamwriter (savedig. filename, false, system. Text. encoding. Default );
Sw. Write (this. textbox1.text );
Sw. Close ();
This. Text = savedig. filename;
}
}
Break;
Case dialogresult. No:
Break;
Case dialogresult. Cancel:
Break;

Default: system. Diagnostics. Debug. Assert (false );
Break;
}
}
}
}

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.