Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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);
} 


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
Posted
Updated 18-Nov-10 22:49pm
v2

The code you say must call the keydown event looks more like you add the event handler of the control twice.
C#
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)



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!
 
Share this answer
 
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.
 
Share this answer
 
Comments
André Kraak 17-Feb-13 7:35am    
I think you intended to comment to a solution, but created a solution instead.

If you have a question about or comment on a given solution use the "Have a Question or Comment?" option beneath the solution. When using this option the person who gave the solution gets an e-mail message and knows you placed a comment and can respond if he/she wants.
Please move the content of this solution to the solution you are commenting on and remove the solution.

Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900