Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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 18-Nov-10 22:44pm
Edited 18-Nov-10 22:49pm
Abhinav S378.4K
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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)
 

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!
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Comments
André Kraak at 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)



Advertise | Privacy | Mobile
Web03 | 2.8.140926.1 | Last Updated 17 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100