C#窗口關閉到最小化

希望能夠幫助一些人

 

private DialogResult result = DialogResult.No;

//Yes關閉窗口,No最小化窗口
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (result == DialogResult.Yes)
{
e.Cancel = false;
Application.Exit();
}
else
{
e.Cancel = true;
this.Hide();
this.Visible = false;
}
}

//關閉按鈕,給result賦值
private void btnExit_Click(object sender, EventArgs e)
{
result=MessageBox.Show("確認退出窗口嗎?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
Application.Exit();
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章