在winform窗体有一个文件控件,对其写了一个Leave事件,可有时关闭窗体时会触发到这个Leave事件,导致出现错误提示,我怎样做到关闭提示不让其触发该事件
if ( MdiParent.ActiveMdiChild.Name != "Quote") { return; }
这样写了好像也没有用
if ( MdiParent.ActiveMdiChild.Name != "Quote") { return; }
这样写了好像也没有用
{
if (CustomerID.SetTextValue == "" || MdiParent.ActiveMdiChild.Name != "Quote") { return; }
System.Data.SqlClient.SqlDataReader sdr = Conn.ReturnDataReader(Conn.GetDb, "select isnull(curcode,''),isnull(Term,'') ,isnull(Priceterm,'') from customer where custcode='" + CustomerID.SetTextValue + "'");
if (sdr == null)
{
MessageBox.Show("你输入的客户" + CustomerID.SetTextValue + "是无效的,请重新确认");
CustomerID.Focus();
return;
} }
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
button1.Leave -= new System.EventHandler(this.button1_Leave);
}
然后通过类似ErrorProvider或状态栏显示你要显示的错误信息呀!
另外我沉得11楼的办法不可行,因为模态窗口的弹出是因为Leave事件的发生,那它为什么会发生呢,因为文本框失去了焦点,那文本框为什么会失去焦点呢?因为用户点击了其它的按钮或是其他的原因,在情况下如果用户点击的是窗体的关闭按钮或可以关闭窗体的普通按钮,则先导致文本框失去焦引发Leave事件进而弹出窗口,然后才会进入窗体关闭的方法!