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.

Advertisements
This entry was posted in cSharp. Bookmark the permalink.

One Response to Using Settings in C# Windows Forms applications

  1. Andrew says:

    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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s