Load-event of UserControls in design mode

· May 15, 2007

Ran into another problem just now…

If you have code in the Load-event of a Windows user control, it will fire when the user control is shown in Visual Studio at design-time. This can be troublesome if the code doesn’t compile or needs some runtime-only variables.

However all Windows forms controls (forms, user controls etc.) inherits from ComponentModel which in turn has a property that’s called DesignMode. This property is true when the Component (control in our case) is shown in design-mode in Visual Studio.

Beware for this special case though

Twitter, Facebook