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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
VulpesRank #55 · 29.2K reputationPosted Jul 24, 2011, 2:06 AM EDT
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.
Sam HobbsRank #108 · 20.5K reputationPosted Jul 24, 2011, 12:16 PM EDT
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.
lily A9 reputationPosted Aug 14, 2011, 10:32 AM EDT