Here it is suggested to use this to get the scroll event produced with the mouse wheel. I read the official documentation but still do not know how to use this in C#. I have code mostly from this answer.
My code is this:
internal class EnhancedListView : ListView
{
internal event ScrollEventHandler ScrollEnded,
ScrollStarted;
const int WM_NOTIFY = 0x004E;
internal EnhancedListView()
{
Scroll += EnhancedListView_Scroll;
}
ScrollEventType mLastScroll = ScrollEventType.EndScroll;
private void EnhancedListView_Scroll(object sender, ScrollEventArgs e)
{
if (e.Type == ScrollEventType.EndScroll)
{
ScrollEnded?.Invoke(this, e);
}
else if (mLastScroll == ScrollEventType.EndScroll)
{
ScrollStarted?.Invoke(this, e);
}
mLastScroll = e.Type;
}
internal event ScrollEventHandler Scroll;
protected virtual void OnScroll(ScrollEventArgs e)
{
Scroll?.Invoke(this, e);
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == 0x115)
{
// WM_VSCROLL
OnScroll(
new ScrollEventArgs(
(ScrollEventType)(m.WParam.ToInt32() & 0xffff),
0
)
);
}
else if (m.Msg == WM_NOTIFY)
{
// What should I put here?
}
}
}