我以前从未发生过这种情况。
我在uses子句下确实有System.Windows.Forms命名空间,并且我能够使用DialogResult的属性。看下面的代码。这就是我的程序中的问题所在。
if (thewinform.ShowDialog=DialogResult.OK) then
我确实调试了它并打开了 winform 对话框。一旦我单击“确定”按钮并返回检查 DialogResult,它就会跳过 if 代码块。此时,我注意到 DialogResult 实际上是 NIL
我以前从未遇到过这样的事情。
有什么想法吗?谢谢,
最佳答案
我找到了问题的答案。
当您想将 winform 纯粹用作对话框时,则不能有 FormClosing 事件。
对于我的 thewinform,我不小心创建了它的 FormClosing 事件并忘记了它。
method thewinform.thewinform_FormClosing(sender: System.Object; e: System.Windows.Forms.FormClosingEventArgs);
begin
e.Cancel := true;
hide;
end;
一旦我删除了这个 winform 事件,ShowDialog 和 DialogResult 就会按预期运行。
这与另一个 stackoverflow 问题 Why does ShowDialog always return DialogResult.Cancel? 非常相似。
关于winforms - 为什么对话结果为零?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13032870/