C# ShowDialog 如何验证后再DialogResult.OK

zygweb 2015-07-31 11:50:32
一、主form
frmAddCar fa = new frmAddCar();
fa.ShowDialog();
if (fa.DialogResult == DialogResult.OK)
{
//接收返回值
}

二、showDialo窗体
//button按钮已设置this.btn_ok.DialogResult = System.Windows.Forms.DialogResult.OK;
private void btn_ok_Click(object sender, EventArgs e)
{
//验证通过再关闭窗体,否则不关闭
}
三、现在问题
不管验证通过否,都会关闭showDialo窗体。如何让其验证不通过就不关闭showDialo窗体,只有通过在关闭。
...全文
534 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
by_封爱 版主 2015-07-31
  • 打赏
  • 举报
回复
首先 你的btm_ok这个按钮不需要设置任何DialogResult只需要有click事件即可. 然后 在事件最后 你输出this.DialogResult = DialogResult.OK;或this.DialogResult = DialogResult.NO.的话 会自动关闭当前窗体 那么上个页面就能接收到了.
宝_爸 2015-07-31
  • 打赏
  • 举报
回复
The dialog result of a form is the value that is returned from the form when it is displayed as a modal dialog box. If the form is displayed as a dialog box, setting this property with a value from the DialogResult enumeration sets the value of the dialog box result for the form, hides the modal dialog box, and returns control to the calling form. 在对话框中给DialogResult赋值时,就会隐藏这个Dialog.
本拉灯 2015-07-31
  • 打赏
  • 举报
回复
private void btn_ok_Click(object sender, EventArgs e) { 你的业务写在这 if(验证通过) { this.DialogResult = DialogResult.OK; } }
宝_爸 2015-07-31
  • 打赏
  • 举报
回复
在frmAddCar里面验证了。
孤独de猫 2015-07-31
  • 打赏
  • 举报
回复


class frmTest :From
{
   void Onbuttonclick(){
    this.DialogResult = DialogResult.OK;
}
}


frmTest frm = new frmTest();

if(frm.ShowDialog() == DialogResult.OK)
{
   //TODO 
}

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧