As the title says.
History: To reduce flicker in my ListBox with DrawMode.OwnerDrawFixed
and a custom OnDrawItem() I used the subclassing example from this page: http://yacsharpblog.blogspot.no/2008/07/listbox-flicker.html
which uses
SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
It works well except for one thing: When I scroll sideways to see long strings the OnDrawItem() does not seem to understand that it should draw with an offset. It seems like the horizontal scroll offset is lost somewhere on the way and the area OnPaint() has been called to fill in gets filled in by my OnDrawItem() as if the ListBox was not scrolled sideways at all.
Please note: If I disable ControlStyles.UserPaint
and let the system call OnDrawItem() directly, it works fine and I can scroll side-ways normally. But it flickers and is too slow to be useful. I need the custom OnPaint() and the ControlStyles.OptimizedDoubleBuffer
to make it smooth.
Can someone tell me where/how to get the horizontal scroll position, or what needs to be done to make this happen automatically, like when the system calls OnDrawItem?
I found a solution here: http://www.codeproject.com/Articles/7554/Getting-Scroll-Events-for-a-Listbox
That is kind of a hack, since the ListBox simply doesn't expose any properties around the scrollbar, but it works. I used a simplified version where I extract the data directly from msg.WParam without calling any external dll function. OnPaint will be called immediately after anyway, so no reason messing about sending extra scroll events.
This is an internal tool, and it works for me. Solved.