开发者

.NET Control.Update method needed after invalidate?

In my code, just calling .Invalidate does the same thing as if an update is called. In fact, when I c开发者_运维百科all .Update afterward, the flicker for the control seems to be worse. I read on the documentation page the following:

"The Update method just forces the control to be painted immediately"

This is confusing for me as all the online examples of redrawing tell me to specify an invalidated region, then call the update in order to get the least amount of flicker. Based on those examples, I would assume that the update call is mandatory.


This blog post describes the differences between Control.Invalidate and Control.Update

Control.Invalidate(...)

The bool parameter denotes whether the user wants to invalidate the child controls of the control on which he is calling Invalidate. The Rectangle parameter are the bounds to invalidate and the region parameter is the region to invalidate. All the overloads essentially end up calling one of the RedrawWindow, InvaliateRect or InvalidateRgn functions. If RedrawWindow is called then this may result in a WM_PAINT message being posted to the application message queue (to invalidate the child controls).

The important thing to note here is that these functions only “invalidate” or “dirty” the client area by adding it to the current update region of the window of the control. This invalidated region, along with all other areas in the update region, is marked for painting when the next WM_PAINT message is received. As a result you may not see your control refreshing (and showing the invalidation) immediately (or synchronously).

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜