关闭对话框,形式推出的对话框

编程入门 行业动态 更新时间:2024-10-26 16:27:51
本文介绍了关闭对话框,形式推出的对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个WinForms应用程序的形式。当我按下一个按钮,它加载与选项的模式消息框yes和no。

I have a form in a winforms app. When I press a button, it loads a modal message box with the options yes and no.

这是好的,但是当我按不,我要同时关闭。对话框,并在其中推出的对话框(发件人)按钮的形式

This is fine, but when I press no, I want to close both the dialog box and the form where the button which launched the dialog box (the sender) is.

因此,应用程序的结构是这样的:

So the app structure is like this:

主应用程序窗口>按菜单项,启动此表新表(连接设置)>按下按钮启动的消息框。

Main app window > press menu item to launch new form (connection setup) > press button on this form to launch message box.

两个窗口都打开(连接设置形式和对话框),我既想关闭。

Two windows are open (connection setup form and dialog box), which I both want closed.

如何我能做到这一点?

推荐答案

在您的是,没有模态形式,只要设置的DialogResult 来的没有的当您按下的没有的按钮,如:

In your yes-no modal form, just set DialogResult to No when you press the No button, like:

private void noButton_Click(object sender, EventArgs e) { this.DialogResult = System.Windows.Forms.DialogResult.No; }

和模态窗体将自动关闭,当你点击的否

and the modal form will automatically close when you click No

然后当你打开你的模式窗体做这样的事情(在连接设置形式):

Then when you open your modal form do something like this (in the connection setup form):

var modalForm = new YesNoForm(); if (modalForm.ShowDialog() == DialogResult.No) { this.Close(); // close the connection setup form }

修改

我还以为你是 - 没有模态形式是定制的,如果它是一个简单的MessageBox,只是做:

I thought your yes-no modal form was custom, if it's a simple MessageBox, just do:

var dlgResult = MessageBox.Show("Yes or no ?","?",MessageBoxButtons.YesNo); if(dlgResult == System.Windows.Forms.DialogResult.No) { this.Close(); // close the connection setup form }

在其他的答案已经建议

as already suggested in other answers

更多推荐

关闭对话框,形式推出的对话框

本文发布于:2023-11-17 06:29:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609157.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对话框   形式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!