[quoted text, click to view] On Wed, 30 May 2007 06:05:12 -0700, e-mre <EmreT@newsgroup.nospam> wrote:
> Is it possible to add a new record to the settings file at run-time? Or
> is the only possible time to add a new setting is design-time?
Depends on what you mean. The settings you add in the designer are added
as properties to the Settings class. Obviously you can't do that at
run-time.
[quoted text, click to view] > There are many many thing in my application that the user can customize
> for him/her. I am thinking of stroring these in the settings file on the
> user PC but I don't want to open a new record in the settings file for
> each customizable setting.
IMHO, this is not a very useful feature. Your settings file should not be
very large, no matter how many settings you put into it. Further, if it's
a problem for the file to be large enough to contain all possible
settings, then that's a problem for the user who does change all possible
settings. I doubt you're in that situation, but if you are, you need to
reconsider your use of the settings storage.
And of course, if you're not, then it's not a good use of your time to try
to figure out how to avoid writing out settings that are not changed from
the default.
All that said, if you still decide you really want to do this, you should
be able to use the built-in XML-writing support to essentially implement
your own Settings class that does what you want. I think you could
probably override the Save() method in the Settings class (it's defined as
"partial" so you could add new code in a different .cs file), enumerating
the properties yourself and saving only those that differ from the
default. But since I haven't tried that, I don't really know how hard
that would be and what sort of pitfalls await you.