c#鼠标在一个form外点击后 该窗体自动关闭

2024-12-15 22:17:50
推荐回答(2个)
回答1:

private void Form1_Deactivate(object sender, EventArgs e) //每当窗体停用的时候发生的事件,在窗体外面点击,其实就还是窗体失去焦点
{
this.Close();
}

回答2:

private void shutdown(object sender, EventArgs e)
{
this.Close();
} private void Form2_Load(object sender, EventArgs e)
{
this.LostFocus += new EventHandler(shutdown);
}