为什么我的窗体_键盘事件对F1至F12都不起作用,不触发事件?但是其它键却都可以?
private void frmEmployee_KeyPress(object sender, KeyPressEventArgs e)
{
switch (e.KeyChar)
{
case (char)Keys.F9 :
this.Seek();
break;
}
}
========================================
不触发事件的键有: F1--F9,Insert,Delete,Home,End,方向键
其它的都会触发....
为什么?
------解决方案--------------------你可以重写如下这个方法来处理按键信息:
protected override bool ProcessDialogKey(Keys keyData)
{
return base.ProcessDialogKey(keyData);
}
------解决方案--------------------//protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
//{
// if(keyData == Keys.F10)
// {
// key = true;
// }
// return base.ProcessCmdKey(ref msg, keyData);
//}
}
------解决方案--------------------private void frmEmployee_KeyPress(object sender, KeyPressEventArgs e)
{
switch (e)
{
case Keys.F9 :
this.Seek();
break;
}
}
------解决方案--------------------public static ToolBarButtonClickEventArgs ProcessToolbarButton(KeyEventArgs key,ToolBar toolbar)
{
ToolBarButtonClickEventArgs click;
foreach(ToolBarButton button in toolbar.Buttons)
{
if(TransTemp(key.KeyData.ToString()) == button.Text)
{
click = new ToolBarButtonClickEventArgs(button);
return click;
}
}
return null;
}
public static string TransTemp(string KeyText)
{
switch(KeyText)
{
case "F1 ":
return "查询 ";
case "F2 ":
return "修改 ";
case "F3 ":
return "添加 ";
case "F4 ":
return "删除 ";
case "F12 ":
return "帮助 ";
case "Esc ":
return "退出 ";
default:
return " ";
}
private void CompanyInfo_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(ProcessToolbarButton(e,this.toolBar1) != null)
{
this.toolBar1_ButtonClick(this.toolBar1,ProcessToolbarButton(e,this.toolBar1));
}
}
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEv