Windows 窗体对话框结果
在下面的代码中,我想获取表单的对话框结果,但它没有保存到我的变量中......为什么?
我的代码:
public void xyz() {
var dialogResult = new DialogResult();
if (booleanVariable) {
var form1 = new Form1();
form1.ShowDialog();
dialogResult = form1.DialogResult;
}
else {
var form2 = new Form2();
form2.ShowDialog();
dialogResult = form2.DialogResult;
}
if (dialogResult == DialogResult.OK) {
...
}
}
在我的 Form1
和 Form2
处,我设置了 this.DialogResult = DialogResult.OK
。 在该过程结束时,我的变量 dialogResult
是 DialogResult.None
,为什么?
in the following code I want to get the dialog result of a Form but it's not saved to my variable... why?
My code:
public void xyz() {
var dialogResult = new DialogResult();
if (booleanVariable) {
var form1 = new Form1();
form1.ShowDialog();
dialogResult = form1.DialogResult;
}
else {
var form2 = new Form2();
form2.ShowDialog();
dialogResult = form2.DialogResult;
}
if (dialogResult == DialogResult.OK) {
...
}
}
At the and of my Form1
and Form2
i set the this.DialogResult = DialogResult.OK
.
At the end of the process my variable dialogResult
is DialogResult.None
, why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用您的
IF
语句修改它:try to modify this with your
IF
Statement: