c# - Custom ScrollEventHandler not returning NewValue upon scrolling -



c# - Custom ScrollEventHandler not returning NewValue upon scrolling -

can tell me i'm doing wrong here. created own scrolleventhandler within custom listview more control. onscroll function gets called whatever reason newvalue 0 , oldvalue -1. reason why it's not beingness updated correctly?

public class listviewxp : system.windows.forms.listview { ... [dllimport("user32.dll")] public static extern int getscrollpos(intptr hwnd, int nbar); private const int sb_horz = 0; private const int sb_vert = 1; public delegate void scrolleventhandler(object sender, scrolleventargs e); public event scrolleventhandler scroll; protected virtual void onscroll(scrolleventargs e) { scrolleventhandler handler = this.scroll; if (handler != null) handler(this, e); } protected override void wndproc(ref system.windows.forms.message m) { base.wndproc(ref m); if (m.msg == wm_hscroll || m.msg == wm_vscroll) { int scrollpos = 0; if (m.msg == wm_hscroll) scrollpos = getscrollpos(this.handle, sb_horz); else scrollpos = getscrollpos(this.handle, sb_vert); onscroll(new scrolleventargs((scrolleventtype)(m.wparam.toint32() & 0xffff), scrollpos)); } } .. } listview1.scroll += new listviewxp.scrolleventhandler(listview1_onscroll); private void listview1_onscroll(object sender, scrolleventargs e) { console.writeline(e.newvalue.tostring()); console.writeline(e.oldvalue.tostring()); }

within wndproc creating scrolleventargs object gets used in listview1_onscroll. you're setting newvalue 0, , not setting oldvalue @ all.

try this:

protected override void wndproc(ref system.windows.forms.message m) { base.wndproc(ref m); if (m.msg == wm_hscroll || m.msg == wm_vscroll) { int scrollpos = 0; if (m.msg == wm_hscroll) scrollpos = getscrollpos(this.handle, sb_horz); else scrollpos = getscrollpos(this.handle, sb_vert); onscroll(new scrolleventargs((scrolleventtype)(m.wparam.toint32() & 0xffff), scrollpos)); } }

if want set oldvalue you'll need store newvalue fellow member variable , utilize overloaded constructor scrolleventargs.

c# winforms scroll

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -