本文介绍了捕获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

推荐答案

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!



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

08-22 17:23