The DesignMode Property


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.




Windows Forms 2.0 Programming
Windows Forms 2.0 Programming (Microsoft .NET Development Series)
ISBN: 0321267966
EAN: 2147483647
Year: 2006
Pages: 216

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net