读书人

VB.net中怎样给一个button加入快捷键!

发布时间: 2012-05-21 18:04:41 作者: rapoo

VB.net中怎样给一个button加入快捷键!
如题,vb.net winForm中怎样给一个窗体的按钮添加快捷键,如button按钮,按个键盘上的加号,就等于Enter事件。

[解决办法]
将窗体的keypress属性设为true,然后在窗体的keydown中写代码

VB.NET code
 If e.KeyChar = CChar(ChrW(Keys.Enter)) Then             Button_Click()    End If
[解决办法]
RegisterHotKey注册+号热键
然后重载WndProc

C# code
            [System.Runtime.InteropServices.DllImport("user32.dll")] //申明API函数            public static extern bool RegisterHotKey(             IntPtr hWnd, // handle to window              int id, // hot key identifier              uint fsModifiers, // key-modifier options              Keys vk // virtual-key code             );        protected override void WndProc(ref Message m)        {            //try            //{                const int WM_HOTKEY = 0x0312;//如果m.Msg的值为0x0312那么表示用户按下了热键                switch (m.Msg)                {                    case WM_HOTKEY:                        ProcessHotkey(m);//按下热键时调用你自己的button的方法                        break;                base.WndProc(ref m);        } 

读书人网 >VB Dotnet

热点推荐