【发布时间】:2014-06-05 10:54:20
【问题描述】:
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;
}
}
与持有 Control 相关的所有内容都不会显示在表单标题中... 这只是代码示例,而不是真正的项目。在实际项目中,我需要捕捉 Control + C / X / V 按下来进行复制/粘贴操作。
【问题讨论】:
-
您只是在测试错误的密钥。如果您想查看 Ctrl 键本身,而不仅仅是修饰符,那么您必须测试 Keys.ControlKey。没有意义。
标签: c# .net winforms controls keydown