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.

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.

Comments

Loading...
roncli.com Media Player