Windows Forms 2.0 Programming (Microsoft .NET Development Series)
To change the behavior of a component depending on whether it's executing at design time or run time, you need to know that you're running in a designer. This information is provided by Component's DesignMode property, which returns true at design time or returns false at run time and during the execution of a component's constructor at design time. Using DesignMode makes it relatively simple to prevent AlarmClockControl from constantly repainting at design time: void timer_Tick(object sender, EventArgs e) { ... // Don't do anything if executing at design time if( this.DesignMode ) return; ... // Refresh clock face this.Invalidate(); } Note that Component.DesignMode reports that a component is operating in the design time only if the component has been sited. Because the design time sets the ISite reference after it instantiates a component, you can't inspect Component.DesignMode from a component's constructor. |
Категории