怎么给工具栏和菜单加上快捷键或助记符?

解决方案 »

  1.   

    Public enum KeyModifiers{None=0,Alt=1,Control=2,Shift=4,Windows=8}
    //注册系统热键:
    [DllImport(“user32.dll”,SetLastError=true)] public static extern bool RegisterHotKey(
      IntPtr hwnd, int id, KeyModifiers fsModifiers,
      Keys vk
    );
    //释放:
      [DllImport(“user32.dll”,SetLastError=true)] public static extern bool UnregisterHotKey(IntPtr hwnd,int id);
    //定义快捷键(ctrl+S):
      Bool success=RegisterHotKey(Handle,100,KeyModifiers.Control,Keys.S);
    Protected override void WndProc(ref Message m)
    { const int WM_HOTKEY=0x0312;
      If(m.Msg==WM_HOTKEY)
        {ProcessHotKey(); //热键处理程序,连到button.click就可以了
    }
       Base.WndProc(ref m);
    }
      

  2.   

    如果是菜单的话 选中某个菜单比如 File的open这个
    属性里面的 ShortCutKeys属性里面设置