Saving textbox data [VS 2005]
Hi i was wondering if anyone can help me, ive setup applicationsettings databinding to the textboxes to save the information inputed. But it only saves the information during the session the application is open. Was wondering if any one can help me so when the application is closed it will save the information in the textboxes and reload it once the application as been open. Thx in advance!
Re: Saving textbox data [VS 2005]
In VB the application properties are saved automatically by default. That's part of the VB application framework which is one of the ways that the new VB makes programming easier. C# doesn't include that feature but it's still not hard to save your properties. Place the following code somewhere where it will be executed when the app has finished executing, like the Closed event handler of the main form:
Code:
Properties.Settings.Default.Save();
Re: Saving textbox data [VS 2005]
i have tryed adding it to private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
but it returns back
saying Error 2
The name 'Properties' does not exist in the current context
I am new to C# could you please help me more
Re: Saving textbox data [VS 2005]
is there no form_unload? I am newish to c# to but I don't get an error when compiling my project with a form_unload as below. Might be worth a try.
Code:
private void Form1_UnLoad(object sender, EventArgs e)
{
Properties.Settings.Default.Save();
}
Others will correct me if I am wrong! ;)
Re: Saving textbox data [VS 2005]
it still comes up with the same error :(
Re: Saving textbox data [VS 2005]
'Properties' is a namespace under the default namespace of your project. Is the namespace of the form in which you're trying to use Properties different to the default namespace for your project? If so then you have several options.
1. Change the namespace of the form to match the project's default namespace. This is the most likely thing to do unless you genuinely want the form in a different namespace to the default for the project.
2. Import the project's default namespace in that form's code file with a 'using' statement at the top of the file.
3. Fully qualify Properties with the project's default namespace.
Note also that there is no Unload event for the Form class. You use FormClosing if you want to prompt the user to do something before closing a form or prevent the form closing for some reason, or FormClosed if you want to do something when the form has closed. Although FormClosing will work too, FormClosed is the more appropriate choice in this case.