解释control的invalidate,update,和refresh方法的区别

考试题目希望正规点的答案... 考试题目希望正规点的答案 展开
 我来答
xiangjuan314
2016-05-09 · TA获得超过3.3万个赞
知道大有可为答主
回答量:2.9万
采纳率:0%
帮助的人:2879万
展开全部
Control.Refresh - does an Control.Invalidate followed by Control.Update.
Refresh: 强制控件使其工作区无效并立即重绘自己和任何子控件。==Invalidate + Update
Control.Invalidate - invalidates a specific region of the Control (defaults to entire client area) and causes a paint message to be sent to the control.Invalidate marks the control (region, or rect) as in need of repainting, but doesn't immediately repaint (the repaint is triggered when everything else has been taken care of and the app becomes idle).
Invalidate: 使控件的特定区域(可以自己设置区域,从而提高性能)无效并向控件发送绘制消息。
将控件标记为需要重绘,但是不会立即执行刷新重绘,等到系统空闲时进行重绘。
Control.Update - causes the Paint event to occur immediately (Windows will normally wait until there are no other messages for the window to process, before raising the Paint event).Update causes the control to immediately repaint if any portions have been invalidated.
Update: 使控件重绘其工作区内的无效区域,立即调用Paint事件。若有无效区域,Update将立即触发重绘。
The paint event of course is where all the drawing of your form occurs. Note there is only one pending Paint event, if you call Invalidate 3 times, you will still only receive one Paint event.Paint: 无处不在。如果你调用3次Invalidate,但是系统将只触发一次Paint事件。

Most of the time Invalidate is sufficient, and advisable as you can do a bunch of invalidations (either explicit or implicit) and then let the control repaint itself when the app is idle. It is advisable to use Update or Refresh when you want the control to immediately repaint because the app will not be idle for a user-noticable period of time.
大多数时候Invalidate已经足够了,当系统要集中进行大量的刷新重绘时,建议使用Invalidate,因为这样系统最终只进行一次刷新,提高了系统性能。如果你想立即执行刷新的时候,建议使用Refresh方法。
二、说法二
Refresh和 Repaint是一样的,它只是简单地调用了Repaint.
Update会导致整个窗口(对于没有窗口的 TGraphicControl来说,就是它的父控件的窗口)立即处理WM_PAINT消息,即重画应该画的部分.
Invalidate使控件所在窗口的控件客户区域(对于TWinControl来说就是它的客户区域,对于TGraphicControl来说就是它的父控件的窗口在它的区域范围内的部分)失效,从而产生一个WM_PAINT消息,但并不马上重绘,直到其它消息处理完或遇到一个Update的调用.
Repaint是立即重绘该控件,在TWinControl中其实就是调用了Invalidate和Update,在TGraphiControl 中分不同情况作了不同处理,逻辑稍复杂一些,但功能是一样的.
匿名用户
2016-05-09
展开全部
一、说法一
Control.Refresh - does an Control.Invalidate followed by Control.Update.
Refresh: 强制控件使其工作区无效并立即重绘自己和任何子控件。==Invalidate + Update
Control.Invalidate - invalidates a specific region of the Control (defaults to entire client area) and causes a paint message to be sent to the control.Invalidate marks the control (region, or rect) as in need of repainting, but doesn't immediately repaint (the repaint is triggered when everything else has been taken care of and the app becomes idle).
Invalidate: 使控件的特定区域(可以自己设置区域,从而提高性能)无效并向控件发送绘制消息。
将控件标记为需要重绘,但是不会立即执行刷新重绘,等到系统空闲时进行重绘。
Control.Update - causes the Paint event to occur immediately (Windows will normally wait until there are no other messages for the window to process, before raising the Paint event).Update causes the control to immediately repaint if any portions have been invalidated.
Update: 使控件重绘其工作区内的无效区域,立即调用Paint事件。若有无效区域,Update将立即触发重绘。
The paint event of course is where all the drawing of your form occurs. Note there is only one pending Paint event, if you call Invalidate 3 times, you will still only receive one Paint event.Paint: 无处不在。如果你调用3次Invalidate,但是系统将只触发一次Paint事件。

Most of the time Invalidate is sufficient, and advisable as you can do a bunch of invalidations (either explicit or implicit) and then let the control repaint itself when the app is idle. It is advisable to use Update or Refresh when you want the control to immediately repaint because the app will not be idle for a user-noticable period of time.
大多数时候Invalidate已经足够了,当系统要集中进行大量的刷新重绘时,建议使用Invalidate,因为这样系统最终只进行一次刷新,提高了系统性能。如果你想立即执行刷新的时候,建议使用Refresh方法。
二、说法二
Refresh和 Repaint是一样的,它只是简单地调用了Repaint.
Update会导致整个窗口(对于没有窗口的 TGraphicControl来说,就是它的父控件的窗口)立即处理WM_PAINT消息,即重画应该画的部分.
Invalidate使控件所在窗口的控件客户区域(对于TWinControl来说就是它的客户区域,对于TGraphicControl来说就是它的父控件的窗口在它的区域范围内的部分)失效,从而产生一个WM_PAINT消息,但并不马上重绘,直到其它消息处理完或遇到一个Update的调用.
Repaint是立即重绘该控件,在TWinControl中其实就是调用了Invalidate和Update,在TGraphiControl 中分不同情况作了不同处理,逻辑稍复杂一些,但功能是一样的.
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式