10.10 Forcing a Repaint

 <  Day Day Up  >  

You want to force a repaint of a control or Windows Form to call your rendering code.


Technique

Sometimes, you need to force a form or control to repaint, as is the case with animations. To perform an asynchronous repaint, call the Invalidate or Refresh method. There are several overloaded versions. If you specify no parameters, the entire form repaints. You can also pass a Rectangle or Region object to repaint only a specified area of the form:

 
 private void timer1_Tick(object sender, System.EventArgs e) {     curRotation += 30;     if( curRotation > 360 )         curRotation = 0;     this.Invalidate(); } 

Comments

In most cases, controls automatically update themselves whenever one of their properties changes. Setting the Text property of a TextBox control, for instance, automatically causes the TextBox to update itself. However, when you are working within the realm of GDI+ and custom rendering algorithms, you might have to manually cause a repaint event to occur. This case is especially true when you are performing some type of animation.

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

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