What does invalidate method do?

后端 未结 6 2342
攒了一身酷
攒了一身酷 2021-02-13 13:16

What does invalidate method do in winform app?

Invalidate() method comes with six overloaded for

相关标签:
6条回答
  • 2021-02-13 13:24

    Windows Forms uses GDI for rendering. GDI is the original graphics interface in Windows. DirectX is a newer interface originally created for games development but now also used by higher level frameworks like WPF.

    GDI is based around the concept of a paint method. When a window is displayed Windows will send a paint message to the code responsible for the window. This will lead to the paint method being called. 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. Instead it has to tell Windows that an area needs to be updated. This is called invalidating a region. Windows will then call the relevant paint method supplying information about what is invalid and needs updating. 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.

    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.

    In Windows Forms when you invalidate a control you request that it should be redrawn.

    0 讨论(0)
  • 2021-02-13 13:28

    The Invalidate() method will redraw the control. 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.Invalidate();
    
    0 讨论(0)
  • 2021-02-13 13:29

    It basically calls the PaintBackground and Paint methods of the control.

    0 讨论(0)
  • 2021-02-13 13:33

    Asks windows to redraw the client area of the invalidated window.

    From MSDN:

    "Invalidates the entire surface of the control and causes the control to be redrawn."

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

    0 讨论(0)
  • 2021-02-13 13:46

    It causes the control to be repainted. 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.

    0 讨论(0)
  • 2021-02-13 13:50

    It's a GUI rendering method - it forces windows to redraw the visible portion of the control.

    0 讨论(0)
提交回复
热议问题