Q:

Mouse wheel scrolling Toolstrip menu items

I have some menus that contain many menuitems. Mouse wheel doesn't scroll them. I have to use the keyboard arrows or click the arrows at top and bottom.
Is it possible to use the mouse wheel to scroll toolstrip menu items?
Thanks

A:

A working solution:

Register for MouseWheel event of your form and DropDownClosed event of your root MenuStripItem (here, rootItem) in the Load event of the form
    this.MouseWheel += Form3_MouseWheel;
    rootItem.DropDownOpened += rootItem_DropDownOpened;
    rootItem.DropDownClosed += rootItem_DropDownClosed;

Add the code for Keyboard class which simulate key presses
public static class Keyboard
{
    [DllImport("user32.dll")]
    static extern uint keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

    const byte VK_UP = 0x26; // Arrow Up key
    const byte VK_DOWN = 0x28; // Arrow Down key

    const int KEYEVENTF_EXTENDEDKEY = 0x0001; //Key down flag, the key is going to be pressed
    const int KEYEVENTF_KEYUP = 0x0002; //Key up flag, the key is going to be released

    public static void KeyDown()
    {
        keybd_event(VK_DOWN, 0, KEYEVENTF_EXTENDEDKEY, 0);
        keybd_event(VK_DOWN, 0, KEYEVENTF_KEYUP, 0);
    }

    public static void KeyUp()
    {
        keybd_event(VK_UP, 0, KEYEVENTF_EXTENDEDKEY, 0);
        keybd_event(VK_UP, 0, KEYEVENTF_KEYUP, 0);
    }
}

Add the code for DropDownOpened, DropDownClosed, MouseWheel events:
bool IsMenuStripOpen  = false;

void rootItem_DropDownOpened(object sender, EventArgs e)
{
    IsMenuStripOpen = true;
}

void rootItem_DropDownClosed(object sender, EventArgs e)
{
    IsMenuStripOpen = false;
}

void Form3_MouseWheel(object sender, MouseEventArgs e)
{
    if (IsMenuStripOpen)
    {
        if (e.Delta > 0)
        {
            Keyboard.KeyUp();
        }
        else
        {
            Keyboard.KeyDown();
        }
    }
}

A:

You can enable it application wide with this class:
public class DropDownMenuScrollWheelHandler : System.Windows.Forms.IMessageFilter
{
    private static DropDownMenuScrollWheelHandler Instance;
    public static void Enable(bool enabled)
    {
        if (enabled)
        {
            if (Instance == null)
            {
                Instance = new DropDownMenuScrollWheelHandler();
                Application.AddMessageFilter(Instance);
            }
        }
        else
        {
            if (Instance != null)
            {
                Application.RemoveMessageFilter(Instance);
                Instance = null;
            }
        }
    }
    private IntPtr activeHwnd;
    private ToolStripDropDown activeMenu;

    public bool PreFilterMessage(ref Message m)
    {
        if (m.Msg == 0x200 && activeHwnd != m.HWnd) // WM_MOUSEMOVE
        {
            activeHwnd = m.HWnd;
            this.activeMenu = Control.FromHandle(m.HWnd) as ToolStripDropDown;
        }
        else if (m.Msg == 0x20A && this.activeMenu != null) // WM_MOUSEWHEEL
        {
            int delta = (short)(ushort)(((uint)(ulong)m.WParam) >> 16);
            handleDelta(this.activeMenu, delta);
            return true;
        }
        return false;
    }

    private static readonly Action<ToolStrip, int> ScrollInternal
        = (Action<ToolStrip, int>)Delegate.CreateDelegate(typeof(Action<ToolStrip, int>),
            typeof(ToolStrip).GetMethod("ScrollInternal",
                System.Reflection.BindingFlags.NonPublic
                | System.Reflection.BindingFlags.Instance));

    private void handleDelta(ToolStripDropDown ts, int delta)
    {
        if (ts.Items.Count == 0)
            return;
        var firstItem = ts.Items[0];
        var lastItem = ts.Items[ts.Items.Count - 1];
        if (lastItem.Bounds.Bottom < ts.Height && firstItem.Bounds.Top > 0)
            return;
        delta = delta / -4;
        if (delta < 0 && firstItem.Bounds.Top - delta > 9)
        {
            delta = firstItem.Bounds.Top - 9;
        }
        else if (delta > 0 && delta > lastItem.Bounds.Bottom - ts.Height + 9)
        {
            delta = lastItem.Bounds.Bottom - owner.Height + 9;
        }
        if (delta != 0)
            ScrollInternal(ts, delta);
    }
}

