Tormod Fjeldskår
Tormod Fjeldskår

Reputation: 6002

Application settings without saving to app.config

Application settings in Windows Forms is a convenient way to store application-wide properties. However, on my current project, these settings are littered with color definitions which are more or less static, causing noise in app.config. Are there any good way of preventing settings from being written to app.config, simply relying on the default value?

I tried moving the settings in question out as resources, but as far as I can tell, the Windows Forms designer in Visual studio provides no means of assigning color resource values to properties on controls.

Upvotes: 4

Views: 265

Answers (3)

Joel Coehoorn
Joel Coehoorn

Reputation: 416131

Application settings is the right place for all of this information. If you're worried about noise, build a class with properties to hold each of the color attributes you are saving. Mark the class up with the various [Serializable] attributes and you can place it in Application settings just like anything else. Now your "noisy" color settings are nested in the hierarchy and won't clutter up or drown out other, more significant, settings.

Upvotes: 2

Michał Powaga
Michał Powaga

Reputation: 23183

You can use Settings, it's prepared especially for user/machine specific configuration. You can store there simple types or more complicated but then you'll have to (usually) serialize them to XML and store as string.

Upvotes: 1

Chris Townsend
Chris Townsend

Reputation: 3162

Do you have access to a database you could store key value pairs in? Either that, or if they can be transient then you could store them in a dictionary object in memory.

Storing in a resource file sounds like a good idea too. You could just write a routine to iterate through a set of key value pairs.

Upvotes: 0

Related Questions