What does invalidate method do?

后端 未结 6 2325
攒了一身酷
攒了一身酷 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.

提交回复
热议问题