How to make scroll event for ListView

前端 未结 2 871
情话喂你
情话喂你 2021-01-24 14:10

I want to make an event for the scroll in ListView.

I have found something that works, but it only fires the event when using the scrollbar. It does not respond to scro

相关标签:
2条回答
  • 2021-01-24 14:45

    I have found the other constants for making the scroll on the down arrow key and the end key on the keyboard.this is the code for the CustomListView

    using System;
    using System.Windows.Forms;
    
    class MyListView : ListView
    {
        public event ScrollEventHandler Scroll;
        private const int WM_HSCROLL = 0x114;
        private const int WM_VSCROLL = 0x115;
        private const int MOUSEWHEEL = 0x020A;
        private const int KEYDOWN = 0x0100;
    
        protected virtual void OnScroll(ScrollEventArgs e)
        {
            ScrollEventHandler handler = this.Scroll;
            if (handler != null) handler(this, e);
        }
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);
            if (m.Msg == MOUSEWHEEL || m.Msg == WM_VSCROLL || (m.Msg == KEYDOWN && (m.WParam == (IntPtr)40 || m.WParam == (IntPtr)35)))
            {
                // Trap WM_VSCROLL 
                OnScroll(new ScrollEventArgs((ScrollEventType)(m.WParam.ToInt32() & 0xffff), 0));
            }
        }
    }
    
    0 讨论(0)
  • 2021-01-24 15:00

    The mouse wheel m.Msg value should be:

    private const int WM_MOUSEWHEEL = 0x020A;
    
    0 讨论(0)
提交回复
热议问题