How to keep user input after closing ?
How to keep user input in (textbox, combobox and so on ) after closing the form? i want to keep it till it is changed by the user .....
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
lily APosted Aug 14, 2011, 2:32 PM
Sam HobbsPosted Jul 24, 2011, 4:16 PM
A common way to do what you are asking is to store the data as a "Setting". In your project in the Solution Explorer there should be a "Properties" node; when you expand that, you can double-click on "Settings.settings". A window will be opened showing a grid with columns for names, types, scopes and values. You can create a name for a setting and then use the defaults. The default type is string and the default scope is User. Then at the beginning of your program (such as in the form's Load event) get the value from "Properties.Settings.Default.SettingName" where SettingName is the name you specified. Then at the end (such as the form's Closed event) save the settings. Then .Net will take care of writing the values to a XML file and getting them form it.
VulpesPosted Jul 24, 2011, 6:06 AM
Unfortunately, forms are too complicated to be serialized so you'll have to save the data 'manually'. A simple text file or an XML file should suffice though you will, of course, need to devise a suitable format so you can easily recover the data.
If you have multiple files in your application and you only want to close one (which may be reopened subsequently in the same session) rather than the whole application then, as an alternative to a disk file, you could save the data within memory to a global variable or variables. I'd be inclined to design a custom class which you can create an instance of containing the data and then assign that to the global variable from the form's FormClosed eventhandler. Of course, when the application does eventually close, you will still need to save the data to disk.