gpt4 book ai didi

失效后需要.NET Control.Update 方法吗?

转载 作者:行者123 更新时间:2023-12-04 06:21:11 25 4
gpt4 key购买 nike

在我的代码中,仅调用 .Invalidate 与调用更新的作用相同。事实上,当我之后调用 .Update 时,控件的闪烁似乎更糟。我在文档页面上阅读了以下内容:

“Update 方法只是强制立即绘制控件”

这让我很困惑,因为所有重绘的在线示例都告诉我指定一个无效区域,然后调用更新以获得最少的闪烁。基于这些示例,我认为更新调用是强制性的。

最佳答案

这篇博文描述了差异 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.

关于失效后需要.NET Control.Update 方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6537199/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com