Music. Coding. Gaming. Life.

Got nasty VB.Net ListView flicker? Double Buffer it

Posted Monday, November 28th, 2005 8:30:00 am
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.

<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
        End If
    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.

Imports System.Windows.Forms

Public Class ListViewDoubleBuffered
    Inherits ListView

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

End Class

Bam. Instant double buffered control.


Loading... Media Player