TextBox_Leave事件不是说“鼠标离开TextBox”,而是说TExtBox没有得到聚焦的时候,才会发生此事件。而要是得TextBox被聚焦,就必须在form_Load时候使用textbox1.Focus()。那么当鼠标点击其它控件的时候,使得当前的TextBox_leave控件被触发,从而弹出框框来。
因为是“鼠标离开了textbox”,使得textbox得不到焦点,所以LostFocus总是优先于leave事件(lostfoucs是因,leave是果)。
你可以做一个实验证明:

【代码】
namespace WinFormCSharp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
textBox1.LostFocus += new EventHandler(textBox1_LostFocus);
}
void textBox1_LostFocus(object sender, EventArgs e)
{
MessageBox.Show("LostFocus事件");
}
private void textBox1_Leave(object sender, EventArgs e)
{
MessageBox.Show("leave事件");
}
private void Form1_Load(object sender, EventArgs e)
{
textBox1.Focus();
}
}
}
启动程序,你点击button1看看事件的先后顺序就知道了。
PS:我没有出现你的问题。
如果你有其它意见或私下交流,请直接发送maledong_work@foxmail.com;或者
If you do not have QQ, please
open the page and download it
and click the image to talk or leave message for me.
下载MSDN桌面工具(Vista,Win7)
我的博客园
慈善点击,点击此处