捕获KeyDown或KeyPress上的Tab键 [英] capture Tab key on KeyDown or KeyPress

查看:375
本文介绍了捕获KeyDown或KeyPress上的Tab键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试捕获KeyDown或KeyPress上的Tab键但是它不起作用所以我使用波纹管代码来捕获Tab键



I am trying to capture Tab key on KeyDown or KeyPress But its not working So i use bellow code to capture the Tab key

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
 if (keyData == Keys.Tab)
 {
    MessageBox.Show("Tab KEy Pressed");
 
 }
 return base.ProcessCmdKey(ref msg, keyData);
} 





此代码是woking ..现在我试图从上面的代码中调用控件的keydown事件/>
i尝试以下代码



This Code is woking..Now i am trying to call keydown event of a control from above code
i try following code

Control c =this.ActiveControl;
c.KeyDown+=new KeyEventHandler(c.KeyDown);

但它不是在按摩......

请帮助

but it is not woking...
Pls Help

推荐答案

你说的代码必须调用keydown事件看起来更像是添加控件的事件处理程序两次。

The code you say must call the keydown event looks more like you add the event handler of the control twice.
Control c =this.ActiveControl;
c.KeyDown+=new KeyEventHandler(c.KeyDown);







您应该为每个具有以下签名的控件添加一个事件处理程序:




You should add a event handler to each control which has the following signature:

private void Control_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)







您可以将此处理程序添加到这样的控件中:

c.KeyDown + = new KeyEventHandler(Control_KeyDown);



顺便说一下, ProcessCmdKey 正在覆盖控件的内部例程,而不是事件处理程序。这是两件事。



祝你好运!




You can add this handler to a control like this:
c.KeyDown+=new KeyEventHandler(Control_KeyDown);

By the way, the ProcessCmdKey is overriding an internal routine of a control and is not an event handler. Those are two separate things.

Good luck!


Nijboer先生,



您能否告诉我如何捕获Ctrl键?我想检查鼠标按下时是否按下了Ctrl键。

谢谢。
Hi, Mr. Nijboer,

Could you please tell me how can I capture the Ctrl key ? I want to check if the Ctrl key is pressed when Mouse Down.
Thank you.


这篇关于捕获KeyDown或KeyPress上的Tab键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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