I need a textbox to recall the last entry before it closed last.  
Author Message
robertje





PostPosted: Visual C# General, I need a textbox to recall the last entry before it closed last. Top

I am new to C# and have one problem with my application. I need a textbox to remember the last entry made to it before it closed.

Say, if I type Hello World into the text box and then close the application. When I open the application again I want to see Hello World or what ever else I last typed.

I imagine the answer is pretty easy, but I'm just not getting it. Any help would be great.



Visual C#5  
 
 
Brendan Grant





PostPosted: Visual C# General, I need a textbox to recall the last entry before it closed last. Top

In C# 2.0 (C# Express/Visual Studio 2005) it's quite easy.

Take a look at this Code Project article that walks you through just how to do it.



 
 
ahmedilyas





PostPosted: Visual C# General, I need a textbox to recall the last entry before it closed last. Top

in addition you could also store this to a file and reload it. But overall maybe best to store it in the user settings file to prevent the user from modifying the text from an "open"/easily accessible textfile.

should you wish to read/write to a textfile...

//save:

System.IO.StreamWriter theWriter = new System.IO.StreamWriter(Application.StartupPath + "\\myFile.txt");

theWriter.Write(this.TextBox1.Text);

theWriter.Close();

//open on form load

if (System.IO.File.Exists(Application.StartupPath + "\\myFile.txt"))

{

System.IO.StreamReader theReader = new System.IO.StreamReader(Application.StartupPath + "\\myFile.txt");

if (theReader.EndOfStream == false)

{

this.TextBox1.Text = theReader.ReadLine();

}

theReader.Close();

}



 
 
robertje





PostPosted: Visual C# General, I need a textbox to recall the last entry before it closed last. Top

I understand the concept of the user settings now, but I am still stuck on how to do the same thing with a text box input.
 
 
robertje





PostPosted: Visual C# General, I need a textbox to recall the last entry before it closed last. Top

Never mind, I got now. Thank you for your help. My app is just complete now.