View previous topic :: View next topic |
Author |
Message |
Hernan Martinez
Joined: 19 Nov 2009 Posts: 13
|
Posted: Mon Jan 18, 2010 4:30 pm Post subject: DesignMode |
|
|
While evaluating Globalizer we were faced with the problem of having initializing code in our Forms and Controls constructors. The proposed solution--overloading the default constructor--impose us an important penalty because it would imply a global API change for every consumer.
Theoretically this is what Control.DesignMode property is for but regretably it doesn't always work (for instance, Visual Studio doesn't honor it when designing UserControls).
Fortunatly we found out that the hack for Controls that avoid the VS bug also works for Globalizer and Forms. Just override DesignMode to:
Code: |
[Browsable(false)]
public new bool DesignMode {
get {
return (AppDomain.CurrentDomain.FriendlyName == "DefaultDomain");
}
} |
I didn't find any mention of this hack in the help and forums and I think that some of you might prefer it over default constructor overload.
Regards,
-Hernán. |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Mon Jan 18, 2010 11:08 pm Post subject: |
|
|
Thanks for the suggestion - we may include that in the help for future releases as an alternative. _________________ Infralution Support |
|
Back to top |
|
|
Hernan Martinez
Joined: 19 Nov 2009 Posts: 13
|
Posted: Tue Jan 19, 2010 10:10 am Post subject: |
|
|
I think it's understood in the OP but just to be clear, the programmer should put the external dependency initializer code inside a DesignMode test. IE:
Code: |
public MyForm MyForm() {
InitializeComponent();
if (!this.DesignMode) {
// other initializers.
OpenDatabase(); // or whatever.
}
} |
Also works for UserControl.
Regards,
-Hernán. |
|
Back to top |
|
|
|