Control. invalidate method: invalidates a specific area of the Control and sends a draw message to the control.
Normally, when invalidate () is used to make the region invalid, the re-painting of the control can be triggered, but the re-painting is not triggered under some conditions.
For example:
Private void button#click (Object sender, eventargs E)
{
Textbox1.text = "888 ";
Textbox1.invalidate ();
// Textbox1.update ();
// Textbox1.refresh ();
Thread. Sleep (5000 );
Textbox1.text = "999 ";
}
This is because the thread. Sleep (5000) clause exists. Although textbox1 is invalidate (), "888" is not displayed, but 999 is displayed 5 seconds later.
Use textbox1.update (); or textbox1.refresh.
Control. Update method: enables the control to repaint invalid areas in its workspace.
Control. Refresh method: forces the control to invalidate its Workspace and immediately redraws itself and any child control;
It is equivalent to setting the invalidate method to true and using this method with update.
So now that update is available, why does invalidate still exist?
The reason is that invalidate has a version that is overloaded, for example, invalidate (rectangle, Boolean) invalidates the specified region of the control (add it to the update region of the control, the next draw operation will re-draw the update area), and send a draw message to the control. The sub-control assigned to the control is invalid.
In fact, the invalidate method controls the content to be drawn or re-drawn. The update method controls the time when the painting or re-drawing occurs (that is, the re-drawing name is executed ).