How do I serialize and deserialize my main form (and its controls, subcontrols, their values, etc.)?
Edit, for clarification. Currently I am writing the current value of each control to an .INI file, one by one and reading it back when the program is next run. Every time I add a new control, I have to remember to update that save/load .INI code.
I just wondered if I can do it in one call, or a simple for loop iterating over all controls on the form.
Btw, I use only simple controls like edit box, radio button, combo box, checkd listbox, the most complex thing I have is a datagrid, but even that is not linked to a databse.
Accepted answer “can’t. I will probably code my own, along the lines of …
for each child control (recursivley)
if conrol is editbox ...
if control is radiobutton ...
if ... etc
write control name to .ini file
write control "value" to .ini file
maybe later add left/top/height/width/enabled/visible, etc, bu tfor not th econtrol name an its “value” are enough (text, value, lines, checked?, etc)
There’s no out-of-the-box support for serializing .NET forms and controls. Controls are not marked with the [Serializable] attribute.
I think most of the difficulty revolves around .NET controls that are really wrappers of native Win32 controls. Persisting the native state as XML, it seems, would be infeasible.
Perhaps someone has written a custom serializer; if not, you may need to roll your own.
Edit:
I found this discouraging accepted answer on experts exchange: