Girish1984
Girish1984

Reputation:

Handling multiple key-press event on C# windows form

Is there a way to handle the multiple key-press event on a C# windows form, like Ctrl+E ?

Here's my code:

private void frmDataEntry_KeyDown(object sender, KeyEventArgs e)  
{  
   if (Control.ModifierKeys == Keys.Control && e.KeyCode == Keys.E)
   {  
          //Code  
   }              
}

This condition is always false .. why? I press Ctrl+E and e.KeyCode is false and Control.ModifierKeys is true? What am I doing wrong?

Upvotes: 2

Views: 4785

Answers (2)

Leaf Garland
Leaf Garland

Reputation: 3687

I think the condition you're looking for is

if (e.Control && e.KeyCode == Keys.E)
{
    // code
}

Upvotes: 3

Can Berk Güder
Can Berk Güder

Reputation: 113280

It should be:

if (e.Modifiers == Keys.Control && e.KeyCode == Keys.E) {
    //Code
}

Control.ModifierKeys is for onClick events and the like.

Upvotes: 8

Related Questions