前沿拓展:
dialogresult
樓上的說的挺仔細(xì)了,這是一個(gè)例子,運(yùn)行下就知道了.
string message = “You did not enter a server name. Cancel this operation?”;
string caption = “No Server Name Specified”;
MessageBoxButtons buttons = MessageBoxButt石編至型刻幾步酸ons.YesNo;
DialogResult
拓展知識(shí):
dialogresult
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
MessageBox.Show("提示?", "是否確認(rèn)退出?",MessageBoxButtons.OKCancel,MessageBoxicon.information)
}
其實(shí)不用判斷.點(diǎn)擊窗口右上角的X,會(huì)彈出對話框,如果選擇是OK的話,會(huì)關(guān)閉窗口,點(diǎn)取消相當(dāng)與什么都沒做
dialogresult
this.Dispose(); //釋放資源
this.Close(); //關(guān)閉程序(窗口)
dialogresult
取消按鈕是自己設(shè)計(jì)的話,直接把form 的cancel result button設(shè)置成這個(gè)button;
或者在點(diǎn)擊button的時(shí)候this.dialogresult=cancel;
dialogresult
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("確定關(guān)閉窗口?", "", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
{
e.Cancel = true;
}
}
原創(chuàng)文章,作者:九賢生活小編,如若轉(zhuǎn)載,請注明出處:http://www.drmqd.com.cn/33436.html