鼠标滚轮滚动工具条菜单项 [英] Mouse wheel scrolling Toolstrip menu items

查看:168
本文介绍了鼠标滚轮滚动工具条菜单项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含许多菜单项一些菜单。鼠标滚轮不会滚动它们。我必须使用键盘箭头,或单击箭头在顶部和底部。
是否可以使用鼠标滚轮滚动工具条的菜单项?
谢谢

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

推荐答案

一个有效的解决方案:


  1. 注册表单的鼠标滚轮事件和 DropDownClosed 你的根事件 MenuStripItem (这里,rootItem)在加载的形式

  1. 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;


  • 添加键盘代码类模拟按键

    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);
        }
    }
    


  • 添加代码 DropDownOpened DropDownClosed 鼠标滚轮事件:

    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();
            }
        }
    }
    


  • 这篇关于鼠标滚轮滚动工具条菜单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆