日期:2014-05-17 浏览次数:21201 次
构造函数
setKeyDown(this.Controls);
setKeyUp(this.Controls);
}
private void setKeyDown(Control.ControlCollection conc)
{
foreach (Control ctl in conc)
{
ctl.KeyDown += new KeyEventHandler(ctl_KeyDown);
if (ctl.HasChildren)
{
setKeyDown(ctl.Controls);
}
}
}
//按钮按下
void ctl_KeyDown(object sender, KeyEventArgs e)
{
MessageBox.Show("按下按钮"+e.KeyCode.ToString(), "KeyDown", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
private void setKeyUp(Control.ControlCollection conc)
{
foreach (Control ctl in conc)
{
ctl.KeyUp += new KeyEventHandler(ctl_KeyUp);
if (ctl.HasChildren)
{
setKeyUp(ctl.Controls);
}
}
}
//按钮抬起
void ctl_KeyUp(object sender, KeyEventArgs e)
{
MessageBox.Show("按钮抬起"+e.KeyCode.ToString(), "KeyUp", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}