首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#关于windows form的dialogresult的有关问题

2012-04-11 
C#关于windows form的dialogresult的问题我自己写了一个form,OK按钮设置为返回dialogresult.ok,但是不想点

C#关于windows form的dialogresult的问题
我自己写了一个form,OK按钮设置为返回dialogresult.ok,但是不想点这个按钮之后关闭窗口,想还是通过在form对应的代码中用this.close()关闭窗口,请问这个应该怎么设置呢?

[解决办法]
把这个if(xxx.dialogresult.ok)
{
 xxxxx;
}
else
{
 e.cancel = true;
}
放到form_closing下

然后按钮事件
this.close(); 窗体关闭之前会调用form_closing 也就会出现提示框了.
[解决办法]
在Form1_FormClosing事件里写如下代码

C# code
if (MessageBox.Show("您确认要退出吗?", "退出系统", MessageBoxButtons.OKCancel) == DialogResult.OK)            {                this.Dispose();               // Application.Exit();            }            else                e.Cancel = true; 

热点排行