Reputation:
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
Reputation: 3687
I think the condition you're looking for is
if (e.Control && e.KeyCode == Keys.E)
{
// code
}
Upvotes: 3
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