1 private void Two_KeyDown(object sender, KeyEventArgs e)
2 {
3 if (e.Control & e.KeyCode == Keys.A)
4 {
5 if (this.WindowState==FormWindowState.Normal)
6 {
7 this.WindowState = FormWindowState.Minimized;
8 }
9 else if (this.WindowState==FormWindowState.Minimized)
10 {
11 this.WindowState = FormWindowState.Normal;
12 }
13 }
14 }
在窗体的keyDown时间中写
通过keydown keyup 事件
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
const int WM_KEYDOWN = 0x100;
const int WM_SYSKEYDOWN = 0x104;
if ((msg.Msg == WM_KEYDOWN) ||(msg.Msg == WM_SYSKEYDOWN))
{
switch (keyData)
{
case Keys.Down:
this.Parent.Text = "向下键已经被捕捉";
break;
case Keys.Up:
this.Parent.Text = "向上键已经被捕捉";
break;
case Keys.Left:
this.Parent.Text = "向左键已经被捕捉";
break;
case Keys.Right:
this.Parent.Text = "向右键已经被捕捉";
break;
case Keys.Home:
this.Parent.Text = "Home 键已经被捕捉";
break;
case Keys.End:
this.Parent.Text = "End 键已经被捕捉";
break;
}
}
return base.ProcessCmdKey(ref msg, keyData);
}
public Form1()
{
InitializeComponent();
this.KeyDown += new KeyEventHandler(Form1_KeyDown); //初始化调用键盘事件
}
void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyValue==119)
{
if (this.Visible==true)
{
this.Visible = false;
}
else if(this.Visible==false)
{
this.Visible = true;
}
}
}