Using Settings in C# Windows Forms applications

It suprised me how poor the documentation is for using Settings with a Windows Form application written in C#. I noticed recently the following article posted on the MSDN site, http://msdn2.microsoft.com/en-us/library/aa730869(VS.80).aspx. However, there is an easier way. Create the settings you want to persist in the projects settings page as normal. Then, rather than hand coding the mapping between the setting file and your UI controls go to the form designer. In the properties of the UI control select Application Settings->Property Bindings. Map the appropriate property (e.g. Text) to the required setting value. All done, well not quite. If you want to persist the changes you need to add the following to the forms closed event…

Properties.Settings.Default.Save();

There all done, persisted settings with only one line of code….nice.

One thought on “Using Settings in C# Windows Forms applications

  1. Andrew February 11, 2007 / 7:16 pm

    dude i read most of your blogs,  u no a hell of a lot of stuff,
    i just popped by to say "hey there" and tell ya i like to play with cs2
    but by the look of it u are in to every thing

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s