Flicker Free Listview in VB.NET 2005

by Pber July 15, 2009 21:33

I write many Windows applications that make use of the Listview.  I also like to multithread my applications to retain the GUI responsiveness.  One downside of this is that I find I get lots of flicker in my listview while the listview loads or during form resizing.  I used to just put up with the flicker because many of the techniques to prevent flicker are quite complex and tend to have unwanted caveats.  There is an easy way...

The simple and easy way to obtain a flicker free listview is to use the Doublebuffered property of the control.  This property is new to .NET v2.0 framework.  This property's sole purpose is to prevent flicker in controls by using a secondary buffer to redraw its surface.  So how it is used.

For some reason this property is protected, so we can't access it directly.  The easy way to use it is to create a derived class that inherits the listview class, and just include the DoubleBuffered property set to True.  Once you have the new class, you just call it instead of the normal listview class and you are good to go.

'Create a new derived listview class
    Public Class listview_NoFlicker
        
Inherits ListView

        
Public Sub New()
            
MyBase.New()
            
Me.DoubleBuffered = True
        
End Sub
    
End Class

'usage:
    'flickering listview
    Dim lv1 As New ListView


    
'non flickering listivew
    Dim lv2 As New listview_NoFlicker

Even though I've demonstrated this on a listview, you can use the DoubleBuffered property on other controls as well.

I've included the code for a simple demo program to demonstrate both a flickering and non flickering listview.  You'll note the GUI will remain responsive because of the threading, but the DoubleBuffered listview will not flicker during load or window resizing.

See link below.

Enjoy.

FlickerFreeLVDemo.zip (14.52 kb)

Tags: , ,

Programming

Comments

7/21/2009 2:58:50 PM #

Sweet.  Finally, exactly what I was looking for.
Thanks

fen United States

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.6.1.0
Theme by Mads Kristensen | Modified by Pber