简体   繁体   English

无效方法有什么作用?

[英]What does invalidate method do?

What does invalidate method do in winform app? invalidate方法在winform应用程序中做了什么?

Invalidate() method comes with six overloaded form inside control class of System.Windows.Forms namespace . Invalidate() 方法System.Windows.Forms 命名空间的 control class中带有六个重载形式。

Thanks..... 谢谢.....

Windows Forms uses GDI for rendering. Windows窗体使用GDI进行渲染。 GDI is the original graphics interface in Windows. GDI是Windows中的原始图形界面。 DirectX is a newer interface originally created for games development but now also used by higher level frameworks like WPF. DirectX是最初为游戏开发创建的新界面,但现在也被更高级别的框架(如WPF)使用。

GDI is based around the concept of a paint method. GDI基于绘制方法的概念。 When a window is displayed Windows will send a paint message to the code responsible for the window. 显示窗口时,Windows将向负责窗口的代码发送绘制消息。 This will lead to the paint method being called. 这将导致调用paint方法。 The paint method should then paint the contents of the window onto the screen. 然后,绘制方法应该将窗口的内容绘制到屏幕上。

When a GDI program wants to update what is displayed it cannot directly paint the updated image onto the screen . 当GDI程序想要更新显示的内容时, 它不能直接将更新的图像绘制到屏幕上 Instead it has to tell Windows that an area needs to be updated. 相反,它必须告诉Windows一个区域需要更新。 This is called invalidating a region. 这称为使区域无效 Windows will then call the relevant paint method supplying information about what is invalid and needs updating. 然后,Windows将调用相关的绘制方法,提供有关无效内容和需要更新的信息。 The paint method should then draw the updated contents to the screen. 然后,绘制方法应将更新的内容绘制到屏幕上。

This method of updating screen contents is also used when windows are dragged across other windows. 当窗口被拖过其他窗口时,也使用这种更新屏幕内容的方法。 When GDI was developed graphics hardware was pretty slow and a lot of work is done inside Windows to cache bitmaps and to only invalidate and update what is changed. 当开发GDI时,图形硬件非常慢,并且在Windows内部完成了很多工作来缓存位图,并且只能使更改的内容失效和更新。

When overlapping windows or child windows are drawn it is done back to front to get the correct layering of visual elements. 当绘制重叠的窗口或子窗口时,它会回到前面以获得正确的视觉元素分层。 This can lead to flicker where a background is erased and drawn followed by other elements in front. 这可能导致闪烁的背景被擦除和绘制,然后是前面的其他元素。 If the redraw speed is slower than the screen refresh you might notice some flickering. 如果重绘速度比屏幕刷新慢,您可能会注意到一些闪烁。 This is a telltale sign of a GDI application perhaps created using Windows Forms. 这是使用Windows Forms创建的GDI应用程序的标志。

In Windows Forms when you invalidate a control you request that it should be redrawn . 在Windows窗体中,当您使控件无效时,您请求重绘它。

Asks windows to redraw the client area of the invalidated window. 要求窗口重绘无效窗口的客户区域。

From MSDN: 来自MSDN:

"Invalidates the entire surface of the control and causes the control to be redrawn." “使控件的整个表面无效并导致重绘控件。”

http://msdn.microsoft.com/en-us/library/598t492a.aspx http://msdn.microsoft.com/en-us/library/598t492a.aspx

It causes the control to be repainted. 它会导致控件重新绘制。 http://msdn.microsoft.com/en-us/library/system.windows.forms.control.invalidate.aspx http://msdn.microsoft.com/en-us/library/system.windows.forms.control.invalidate.aspx

You will rarely need to call this method unless you are doing some low level graphics manipulation. 除非您正在进行一些低级图形操作,否则很少需要调用此方法。

The Invalidate() method will redraw the control. Invalidate()方法将重绘控件。 For example if you use a panel 'panel1', which contains a label and a text box, the following code will redraw both the label and text box (by calling the Paint event) 例如,如果使用包含标签和文本框的面板“panel1”,则以下代码将重绘标签和文本框(通过调用Paint事件)

panel1.Invalidate();

它是一种GUI渲染方法 - 它强制窗口重绘控件的可见部分。

它基本上调用控件的PaintBackground和Paint方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM