Reputation: 4354
I have a System.Windows.Forms.ListView containing numerous items. It was flickering intolerably (as seems to often be the case) so after some searching I decided to do these 2 things in a "ListViewLessFlicker" class.
this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.Opaque, true);
DoubleBuffering didn't have much effect even though it's most commonly given as the solution in these topics, but setting the style opaque to true hugely reduced flickering.
http://www.virtualdub.org/blog/pivot/entry.php?id=273
However it had a side-effect that I can't seem to find a fix for. When I hover my mouse over an item in the ListView it now makes the text bold and very blurry (this doesn't happen unless opaque is true).
Here is a very zoomed in example.
If anybody has a fix or knows why it may be doing this I'd love to know!
Upvotes: 3
Views: 731
Reputation: 187
I had the same problem as you and I found solution in the comments on this page: http://www.virtualdub.org/blog/pivot/entry.php?id=273
You have to create new class like this:
public class BufferedListView : ListView
{
public BufferedListView() : base()
{
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
}
}
and then define your ListView as BufferedListView like this:
ListView myListView = new BufferedListView();
After that blurry text is not a problem any more ;)
Upvotes: 3
Reputation: 17327
I usually do this - reduces flickering when resizing the control. You need to use BeginUpdate()
/ EndUpdate()
to reduce flickering when adding items in bulk. I don't know what may cause the blurring, so I can't advise about that - updatig your video driver may help but don't hold your hopes high.
[System.ComponentModel.DesignerCategory ( "" )]
public partial class ListViewEx : ListView
{
private const int WM_ERASEBKGND = 0x14;
public ListViewEx ()
{
InitializeComponent ();
// Turn on double buffering.
SetStyle ( ControlStyles.OptimizedDoubleBuffer |
ControlStyles.AllPaintingInWmPaint, true );
// Enable the OnNotifyMessage to filter out Windows messages.
SetStyle ( ControlStyles.EnableNotifyMessage, true );
}
protected override void OnNotifyMessage ( Message oMsg )
{
// Filter out the WM_ERASEBKGND message to prevent the control
// from erasing the background (and thus avoid flickering.)
if ( oMsg.Msg != WM_ERASEBKGND )
base.OnNotifyMessage ( oMsg );
}
}
Upvotes: 5