当其他控制按下键时,如何运行表格键 [英] how run form key down when is on other control press key down

查看:69
本文介绍了当其他控制按下键时,如何运行表格键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi
i总是希望运行表单键,即使选择或关注表单中的其他控件。



表单或我的程序例如F5运行一种方法。



我该怎么办?

解决方案

< blockquote> as OriginalGriff说

Quote:

将Form.KeyPreview属性设置为true



 myForm.KeyPreview =  true ; 



重写ProcessCmdKey ()

 受保护 覆盖  bool  ProcessCmdKey( ref 消息消息,键keyData)
{
/// /用于快捷键Ctrl + F

if (keyData ==(Keys.Control | Keys.F))
{
/// /代码运行表格
返回 true ;
}
返回 base .ProcessCmdKey( ref msg,keyData);
}


将Form.KeyPreview属性设置为true,并处理Form.KeyDown事件。


hi i want run the form key down always,even if other control in form is selected or focused.

in form or my program for example F5 run the one method.

how do i?
tnx

解决方案

as OriginalGriff said

Quote:

Set the Form.KeyPreview property to true


myForm.KeyPreview = true;


Override the ProcessCmdKey()

protected override bool ProcessCmdKey(ref Message msg, Keys keyData) 
{
  ////for short cut key Ctrl+F

  if (keyData == (Keys.Control | Keys.F)) 
  {
   ////code to run the form 
    return true;
  }
  return base.ProcessCmdKey(ref msg, keyData);
}


Set the Form.KeyPreview property to true, and handle the Form.KeyDown event.


这篇关于当其他控制按下键时,如何运行表格键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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