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: Coding, Double Buffer, ListView, VB.NET
5 Comments
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.
Micah Epps @ 2/25/2008 09:40:00 AM:
Thanks!!! I can see an improvement already, and my process CPU usage is waaaaaay down.
LearningMan @ 3/13/2009 10:19:00 AM:
Me.SetStyle(ControlStyles.DoubleBuffer, True) Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
All Flicker gone :)
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. :)
Unknown @ 5/10/2010 03:14:00 AM:
Great!! Exactly what I was looking for, thanks.
|