Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
i have written a code on KeyDown event like this
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
     if (e.Alt == true && e.KeyData == Keys.V)
     {
          label4_Click(sender, e);
     }
     else if (e.Alt == true && e.KeyData == Keys.U)
     {
          label5_Click(sender, e);
     }
}

I would like to know when i select Alt & V or U together why is the code not executing?

Note:KeyPreview=true (Form's Property)




Thanks in advance
Posted
Comments
PIEBALDconsult 2-Jun-14 21:31pm    
Set a breakpoint with the debugger.
But what is supposed to happen when a Label is clicked?
agent_kruger 2-Jun-14 22:02pm    
sir, when the label is clicked a form should be opened and i have debugged it but it is not going inside both the scopes.

1 solution

you need to use KeyEventArgs.KeyCode Property[^]

C#
if(e.KeyCode == Keys.V && e.Alt )
{
  label4_Click(sender, e);
}
if(e.KeyCode == Keys.U && e.Alt )
{
  label5_Click(sender, e);
}
 
Share this answer
 
Comments
agent_kruger 2-Jun-14 23:43pm    
thank you sir, it worked perfectly.
DamithSL 2-Jun-14 23:47pm    
you are welcome! :-)

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