views:

563

answers:

3

I have a WinForms user control that, when added to a form, should automatically add some elements to application settings. (Of course, the user should be able to customize/disable this behavior.)

is that advisable? What is the "good" way to do this?

[edit]
The control provides a default implementation for the file menu, the consumer only needs to wire up the menu/toolbar items in the designer, and implement some basic events. Part of this is a recent file list, which by default should be remembered.

I agree that the consumer needs full control whether or not he wants these settings added automatically.

So far, I expose the file list as a public string property, and the consumer can add the code to init and store this from/in the application config. If possible, I'd like to simplify this further so the consumer just provides the settings variable where he wants the setting to be stored (if he wants that at all).

A: 

In your control constructor you can check (LicenseManager.UsageMode == LicenseUsageMode.Designtime) and then check the config entries etc but I think this would be a bad idea

Your control could support config entries if they exist, and have some default behaviour if they did not. That would seem more acceptable to me as a developer

You should use a custom config section either way

You can provide a custom config section handler as part of the control so all that need to be done is wire this section up in the config file if the use wants it

TFD
+1  A: 

I don't think your control should be adding anything to the config file, unless it's been asked to do so.

Still, if the user "opts in" to this, then I think you're going to have to add some designer support to your control. Either through the ToolBoxItem, or through the designer being notified on a new control being added, the designer will then have to create and/or update the configuration information it needs.


Thanks for the clarification. You may want to look at IPersistControlSettings interface, especially what it has to say on the subject of ApplicationSettingsBase. That page should lead you to information on strongly-typed Settings in .NET 2.0. It allows default settings to be baked into a control or other library code, in such a way that if the settings change, the changes persist to the application's config file, either per-user or application-wide.

John Saunders
please see clarification.
peterchen
A: 

I think it depends on how much value you will get from the consumer of the control having a usable experience. Are you selling this control? Is it for internal use? The effort required to create the design time experience would probably be prohibitive if this is for internal use.

Jonathan Parker
It's a toy project - I've fiddled with design time controls, my biggest problem is the bad docs, but I'm not afraid of it :) Please see clarification. Thanks.
peterchen