C # differences between invalidate () Update () Refresh ()

Source: Internet
Author: User

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 ).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.