85 wpf sl operation. txt file

Source: Internet
Author: User

 

 

 

Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Using system. windows;
Using system. Windows. controls;
Using system. Windows. Controls. primitives;
Using system. Windows. input;
Using system. Windows. Media;
Using system. componentmodel;
Using system. IO;

Namespace wpfapplication1
{
Public class editsometext: window {
Static string strfilename = path. Combine (environment. getfolderpath (
Environment. specialfolder. localapplicationdata ),
"Petzold \ editsometext \ aa.txt ");
// Static string strfilename = path. Combine (@ "E: \ 11", "aa.txt ");
Textbox txtbox;
[Stathread]
Public static void main ()
{
Application APP = new application ();
App. Run (New editsometext ());
}
Public editsometext ()
{
Title = "edit some text ";
Txtbox = new Textbox ();
Txtbox. acceptsreturn = true;
Txtbox. textwrapping = textwrapping. Wrap;
Txtbox. verticalscrollbarvisibility = scrollbarvisibility. Auto;
Txtbox. keydown + = new keyeventhandler (txtbox_keydown );
Content = txtbox;
Try
{
Txtbox. Text = file. readalltext (strfilename );
}
Catch {

}
Txtbox. caretindex = txtbox. Text. length;
Txtbox. Focus ();

}
Protected override void onclosing (canceleventargs E)
{
Try
{
Directory. createdirectory (path. getdirectoryname (strfilename ));
File. writealltext (strfilename, txtbox. Text );
}
Catch (exception exc ){
Messageboxresult result = MessageBox. Show (
"File cocould be saved:" + exc. Message +
"\ N close program anyway? ", Title,
Messageboxbutton. yesno,
Messageboximage. Exclamation );
E. Cancel = (result = messageboxresult. No );
}
}
Void txtbox_keydown (Object sender, keyeventargs ARGs)
{
If (ARGs. Key = key. F5 ){
Txtbox. selectedtext = datetime. Now. tostring ();
Txtbox. caretindex = txtbox. selectionstart +
Txtbox. selectionlength;
}
}
}
}

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.