Search code examples
.netwinformsscrolluser-controls

How do I capture MouseWheel events in a UserControl?


I have a UserControl derived control. When the user moves the mouse wheel I'd like to capture that and respond to it.

I've tried using the Scroll event but that doesn't ever seem to fire which I'm guessing is because my control doesn't have (or need) a scroll bar.

I can't find the MouseWheel event in Windows Forms Designer although the docs suggest it should be part of every Control derived element. Again, the docs suggest the UserControl is a derivative, so it should support the event.

What am I missing?


Solution

  • In case anyone else faces this, in the end I simply added some handling in the parent control to call functionality in the user control:

        Form1(void)
        {
            InitializeComponent();
    
            MouseWheel += gcnew MouseEventHandler(this, &Form1::MouseWheelHandler);
        }
    
        void MouseWheelHandler(Object^ sender, MouseEventArgs^ e)
        {
            m_myUserControl->MouseWheel(e->Delta);
        }