< Day Day Up > |
TechniqueSometimes, 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(); } CommentsIn 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 > |