读书人

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

发布时间: 2013-07-09 09:50:48 作者: rapoo

VB.net中怎样给一个button加入快捷键!
如题,vb.net winForm中怎样给一个窗体的按钮添加快捷键,如button按钮,按个键盘上的加号,就等于Enter事件。
[解决办法]
将窗体的keypress属性设为true,然后在窗体的keydown中写代码

 If e.KeyChar = CChar(ChrW(Keys.Enter)) Then
Button_Click()
End If


不知这样可以不?
[解决办法]
RegisterHotKey注册+号热键
然后重载WndProc


[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

热点推荐