roncli.com blog
The blog of roncli
roncli.com blog
roncli.com
blog
Profile
roncli
Houston, Texas, United States
Labels
Coding
CTG Music
Editorials
Games
Miscellaneous
Music
Servers
Silliness
Software
Sports
Trax in Space Beta
Weather
Recent Posts
DataGridView is crap
Track 7 Still Rules
0-0-0+
AJAX not ready for prime time just yet
Where have the days gone?
SQL Server & Visual Studio 2005
CAPTCHA
Due Process
And to top off my night...
A story
Monday, November 28, 2005
Got nasty VB.Net ListView flicker? Double Buffer it
Posted: 2:30:00 AM 5 comments
The solution is so painfully obvious, I wish I had thought of it sooner.

In the designer, all you have to do is change your Inherits line to inherit from the ListView object and remove that Autowhatsit in the InitializeComponent function.

ucListViewDoubleBuffered.Designer.vb:
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class ListViewDoubleBuffered
    Inherits System.Windows.Forms.ListView

    'UserControl overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing AndAlso components IsNot Nothing Then
            components.Dispose()
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        components = New System.ComponentModel.Container()
    End Sub

End Class

Then in the code behind, write a constructor and set its styles appropriately.

ucListViewDoubleBuffered.vb:
Imports System.Windows.Forms

Public Class ListViewDoubleBuffered
    Inherits ListView

    Public Sub New()
        MyBase.New()
        InitializeComponent()
        Me.SetStyle(ControlStyles.DoubleBuffer, True)
        Me.SetStyle(ControlStyles.Opaque, True)
    End Sub

End Class


Bam. Instant double buffered control.

Labels: , , ,




5 Comments

  Blogger roncli @ 5/21/2006 01:24:00 PM:
Don't have VB.Net 2005? Don't worry. You can still get flicker-freeness by making the following changes to the code behind a default user control.

1) Replace the inherits line, located directly under the Public Class line, with this:

Inherits System.Windows.Forms.ListView

2) At the end of Public Sub New, add this:

Me.SetStyle(ControlStyles.DoubleBuffer, True)
Me.SetStyle(ControlStyles.Opaque, True)

Don't forget to build your project before using.

  Blogger Micah Epps @ 2/25/2008 09:40:00 AM:
Thanks!!! I can see an improvement already, and my process CPU usage is waaaaaay down.

  Blogger LearningMan @ 3/13/2009 10:19:00 AM:
Me.SetStyle(ControlStyles.DoubleBuffer, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)


All Flicker gone :)

  Blogger roncli @ 3/13/2009 10:42:00 AM:
Both work in this case. Opaque vs. AllPaintingInWmPaint for other cases, though, would be an interesting topic for another discussion. Perhaps if I run across this issue again, I'll bring it up. Thanks for the input. :)

  Blogger Unknown @ 5/10/2010 03:14:00 AM:
Great!! Exactly what I was looking for, thanks.

Post a Comment