Winform学习(1)--获取键盘事件

要使的窗体能获得键盘事件,方法之一是重写ProcessCmdKey。重写代码如下:

  protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
  If(keyData==Keys.w)//当按下W键时
{

  //此处添加代码
} 

    return true;
}

Ps:返回值是必须的。
PS:需要在窗体上设置KeyPreview属性为True

猜你喜欢

转载自blog.csdn.net/weixin_42132384/article/details/81477994
今日推荐