views:

77

answers:

2

Its a simple config app with 4 checkboxes and 5 textboxes, and all values must persist across sessions.

do I have to serialize the fields and restore them by hand? I really have no idea the best way to approach this.

+5  A: 

You could use the User settings, reading the values on load and saving on exit.

You can find info about the settings and how to retireve anda save it on runtime here.

mapache
A: 

If you are talking an ideal solution, you should think about using MVC (which win forms does NOT encourage), so that all the data you care about comes in an encapsulated, non-UI bound object (ie, the model). The UI form populates itself from the data and the app can retrieve the data when the form is torn down. If the data object implements ISerializable, then you're pretty much done.

If you're talking expedient and are absolutely sure that it will never need to grow or change (which never happens - I only do this in one-off apps), then I would scrape the form contents and write them to an appropriate place (user settings, data files, etc).

If you're talking about building something that makes this as easy as possible with never, ever, having to worry about it ever, ever, ever again, I would see about using data binding, or creating a mapping objects that understand how to map data from objects onto UI elements and out again (for example, you could subclass the main form elements to include a name field or use the initial text field to figure out a key to look up in a serializable hashtable or a property name in an serializable object).

plinth