private void Form1_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Up:
this.Text = "up";
break;
case Keys.Down:
this.Text = "down";
break;
case Keys.Left:
this.Text = "<-";
break;
case Keys.Right:
this.Text = "->";
break;
case Keys.Delete:
this.Text = "delete";
break;
case Keys.Control:
this.Text = "control";
break;
case Keys.Control | Keys.C:
this.Text = "control + c";
break;
case Keys.Control | Keys.X:
this.Text = "control + x";
break;
case Keys.Control | Keys.V:
this.Text = "control + v";
break;
default:
break;
}
}
Everything that related to holding Control do not displays in form header... This is just code example and not real project. In real project I need to catch Control + C / X / V presses to do copy / paste operations.
try this solution :
case (e.Control && e.KeyCode == Keys.C)
EDIT : if it not works, add paranthesis around your code :
case (Keys.Control | Keys.C):
EDIT 2 : and this one :
e.KeyData == (Keys.Control | Keys.V)
EDIT 3: switch on KeyData
switch (keyData) {
// Control+ C
case Keys.Control | Keys.C:
// ...
break;
case Keys.Control | Keys.V:
// ...
break;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.