前沿拓展:
dialogresult
楼上的说的挺仔细了,这是一个例子,运行下就知道了.
string message = “You did not enter a server name. Cancel this operation?”;
string caption = “No Server Name Specified”;
MessageBoxButtons buttons = MessageBoxButt石编至型刻几步酸ons.YesNo;
DialogResult
拓展知识:
dialogresult
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
MessageBox.Show("提示?", "是否确认退出?",MessageBoxButtons.OKCancel,MessageBoxicon.information)
}
其实不用判断.点击窗口右上角的X,会弹出对话框,如果选择是OK的话,会关闭窗口,点取消相当与什么都没做
dialogresult
this.Dispose(); //释放资源
this.Close(); //关闭程序(窗口)
dialogresult
取消按钮是自己设计的话,直接把form 的cancel result button设置成这个button;
或者在点击button的时候this.dialogresult=cancel;
dialogresult
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("确定关闭窗口?", "", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
{
e.Cancel = true;
}
}
原创文章,作者:九贤生活小编,如若转载,请注明出处:http://www.wangguangwei.com/33436.html