Winforms application settings using custom types

I started down the path of saving window size settings in the application settings. The fact that I was repeating the same basic info for each form led me to investigate using a custom type to encapsulate this info. The custom type you want to save will have a couple of properties on it, but when you add it to the application settings, you just configure 1 setting. I couldn’t just use the utility to add my type, I had to edit the file. Here’s the steps:

1) Update the settings.settings file

2) Make your custom type [Serializable] – don’t forget to make the class and properties public

I created a custom type to save window settings. With the following signature for the save settings method:

public void SaveSettings(Form aForm)

I was then able to use the following to save my custom type and its properties. Notice that I use the Default[string] method instead of designer created method like Default.MainForm

Properties.Settings.Default[aForm.Name] = this; //Save my custom type

Properties.Settings.Default.Save();

Print | posted @ Tuesday, November 17, 2009 4:59 PM

Comments on this entry:

No comments posted yet.

Post A Comment
Title:
Name:
Email:
Comment:
Verification: