Saturday, September 21, 2013

Whats the difference between Control.Invalidate, Control.Update and Control.Refresh? - Soaked in CIDER ! - Site Home - MSDN Blogs

Control.Update()

Update function calls the UpdateWindow function which updates the client area of the control by sending WM_PAINT message to the window (of the control) if the window's update region is not empty. This function sends a WM_PAINT directly to WNDPROC() bypassing the application message queue.
Thus, if the window update region is previously “invalidated” then calling “update” would immediately "update" (and cause repaint) the invalidation.
Control.Refresh()

            By now, you might have guessed what Refresh( ) would be doing. Yes, it calls Invalidate(true) to invalidate the control and its children and then calls Update( ) to force paint the control so that the invalidation is synchronous.

So the differences ( Invalidate vs Update vs Refresh ) are:

  • Control.Invalidate() marks the control 'needs to be' repainted in the future.
  • Control.Update() tells the control to repaint now (bypasses the message queue).
  • Control.Refresh() marks the control 'needs to be' repainted and then tells the control to repaint now.
Control.Invalidate should be the least amount of 'work' for the application to do.
But, if in doubt, to make the control look smoother (redraw when you expect it), Refresh() should work.

No comments: