c# - OnDrawItem does not respect horizontal scroll position when called from OnPaint -
as title says.
history: reduce flicker in listbox drawmode.ownerdrawfixed
, custom ondrawitem() used subclassing example page: http://yacsharpblog.blogspot.no/2008/07/listbox-flicker.html uses setstyle(controlstyles.optimizeddoublebuffer | controlstyles.allpaintinginwmpaint | controlstyles.userpaint, true);
it works except 1 thing: when scroll sideways see long strings ondrawitem() not seem understand should draw offset. seems horizontal scroll offset lost somewhere on way , area onpaint() has been called fill in gets filled in ondrawitem() if listbox not scrolled sideways @ all.
please note: if disable controlstyles.userpaint
, let system call ondrawitem() directly, works fine , can scroll side-ways normally. flickers , slow useful. need custom onpaint() , controlstyles.optimizeddoublebuffer
make smooth.
can tell me where/how horizontal scroll position, or needs done make happen automatically, when system calls ondrawitem?
i found solution here: http://www.codeproject.com/articles/7554/getting-scroll-events-for-a-listbox
that kind of hack, since listbox doesn't expose properties around scrollbar, works. used simplified version extract data directly msg.wparam without calling external dll function. onpaint called after anyway, no reason messing sending scroll events.
private int mhscroll; protected override void wndproc(ref system.windows.forms.message msg) { if (msg.msg == wm_hscroll) { switch ((int)msg.wparam & 0xffff) { case sb_pageleft: mhscroll = math.max(0, mhscroll - clientsize.width * 2 / 3); //a page 2/3 width. break; case sb_pageright: mhscroll = math.min(horizontalextent, mhscroll + clientsize.width * 2 / 3); break; case sb_thumbposition: case sb_thumbtrack: mhscroll = ((int)msg.wparam >> 16) & 0xffff; break; } } base.wndproc(ref msg); }
this internal tool, , works me. solved.
Comments
Post a Comment