Application settings without saving in app.config

Application Settings in Windows Forms is a convenient way to store application properties. However, in my current project, these settings are dotted with color definitions that are more or less static, causing noise in app.config. Is there any good way to prevent setting parameters in app.config by simply relying on the default value?

I tried moving the selected options as resources, but as far as I can tell, the Windows Forms Designer in Visual Studio does not provide any means to assign color resource values ​​to properties on controls.

+4
source share
3 answers

Application settings are the right place for all this information. If you are worried about noise, create a class with properties to preserve each of the color attributes that you preserve. Mark the class using various [Serializable] attributes, and you can put it in the application settings just like anything else. Now your “noisy” color settings are nested in the hierarchy and will not clutter or drown out other, more meaningful settings.

+2
source

You can use the Settings , which was specially prepared for the configuration of the user / machine. You can store simple types or more complex ones there, but then you will have to (as a rule) serialize them in XML and store them as a string.

+1
source

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

Saving to a resource file also sounds good. You can simply write a procedure to iterate through a set of key value pairs.

0
source

Source: https://habr.com/ru/post/1380009/


All Articles