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: 使控件的特定区域(可以自己设置区域,从而提高性能)无效并向控件发送绘
制消息。
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:使控件重绘其工作区内的无效区域。 立即调用Paint事件。
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:无处不在
Control.Invalidate方法:使控件的特定区域无效并向控件发送绘制消息。
通常情况下,用Invalidate()使区域无效就可触发该控件的重画了,但在一些条件下却没有
触发重画.
例如:
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = "888";
textBox1.Invalidate();
//textBox1.Update();
// textBox1.Refresh();
Thread.Sleep(5000);
textBox1.Text = "999";
}
这是由于Thread.Sleep(5000)这一句的存在,textBox1虽然Invalidate()了,但并没有显
示"888",而是5秒后直接显示999了.
得用textBox1.Update();或textBox1.Refresh();才行.
Control.Update 方法:使控件重绘其工作区内的无效区域。
Control.Refresh 方法:强制控件使其工作区无效并立即重绘自己和任何子控件;
等效于将 Invalidate 方法设置为 true 并将该方法与 Update 一起使用。
那么既然有了Update,为何还要存在Invalidate呢?
原因是Invalidate有重载的版本例如:Invalidate(Rectangle, Boolean) 使控件的指定
区域无效(将其添加到控件的更新区域,下次绘制操作时将重新绘制更新区域),并向控
件发送绘制消息。还可以使分配给该控件的子控件无效
其实Invalidate 方法控制绘制或重新绘制的内容。Update 方法才是控制发生绘制或重新
绘制的时间(即执行重绘制命名).