Owner Draw ListView “smearing” when scrolling
-
06-09-2019 - |
Question
I have an ownerdrawn ListView that "smears" when I scroll. It only affects the last displayed item as it moves into the visible are of the list...
It looks like:
Blah
Blah
Blah
...have all been drawn on top of each other 1 pixel apart. The code in the DrawItem event is of the form
Rectangle rect = new Rectangle(e.Bounds.X + mIconSize.Width,
e.Bounds.Y, e.Bounds.Width, e.Bounds.Height);
e.Graphics.DrawString(episode.ToString(), this.Font, mBlackBrush, rect);
I'm completely stumped. Any ideas gratefully appreciated! Dave
Solution
You can enable double buffering for ListView by deriving from it and setting DoubleBuffered = true
. There's a noticeable reduction in flicker, especially in Tile view, once you turn Double Buffering on.
OTHER TIPS
In detail view drawing do all of your drawing in DrawSubItem(...). The problem is drawItem is getting called for the first item and DrawSubitem is also for the same item ... with slightly different bounds.
also, int the form's own properties, you can enable DoubleBuffer. additionally, there are a couple of commands you can use.
More information can be found by searching DoubleBuffer C# at google (sorry, as a new user I can't post links).
This is a known bug in the ListView control.