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;
}
}
}
}