When working with .Net forms and user controls, many times there are initialization methods that fire from a load or other event or are called by the constructor. In some cases it is undesirable to have these actions occurring when loading a class into the visual designer.
.Net controls have a DesignMode property that can be evaluated but it is not reliable as it only seems to be correct when the control is at most, a child of the class loaded in the design canvas, not a grandchild or further down the chain. This means that this detection won't be correct when a form contains a user control that contains a user control etc. DesignMode is a protected property so looping up through the parents won't work either.
I've come up with my own method but it seems like there should be something better. My method is to set a static property in a class when _idestartup.p runs. This property can then be read by any of the controls being loaded at design time and the behavior can be altered accordingly.
Is there a better way?
There does not seem to be a better way. We have implemented it this way using a property called DesignTime assigned from the components constructor.