Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does invalidate method do?

Tags:

c#

.net

winforms

What does invalidate method do in winform app?

Invalidate() method comes with six overloaded form inside control class of System.Windows.Forms namespace.

Thanks.....

like image 340
Aryan SuryaWansi Avatar asked Jun 21 '11 12:06

Aryan SuryaWansi


1 Answers

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.

like image 139
Martin Liversage Avatar answered Sep 19 '22 22:09

Martin Liversage