private void Business_KeyUp(object sender, KeyEventArgs e)
{
 if (e.KeyCode == Keys.Enter)//如果热键为回车键,相当于确定查询按钮事件触发
 { }
}上面我做了个窗体回车键,但遇到一个问题,我做查询如果有条件不符合就会弹出一个错误提示消息框,按回车后消息框是没了,但也触发了上面的事件,如何判断排除按下的回车键不是消息框的

解决方案 »

  1.   

    private void Business_KeyUp(object sender, KeyEventArgs e)
    {
     if (e.KeyCode == Keys.Enter)//如果热键为回车键,相当于确定查询按钮事件触发
     {
        this.AcceptButton = null;
     }
     else
     {
        this.AcceptButton = this.button1;
     }
    }
      

  2.   

    private void Business_KeyUp(object sender, KeyEventArgs e)
    {
     if (e.KeyCode == Keys.Enter)//如果热键为回车键,相当于确定查询按钮事件触发
     {
        this.AcceptButton = null;
     }
     else
     {
        this.AcceptButton = this.button1;
     }
    }
    好代码