Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
DialogResult.OK工作不正常C#_C# - Fatal编程技术网

DialogResult.OK工作不正常C#

DialogResult.OK工作不正常C#,c#,C#,问题是,即使我没有单击OK按钮,它仍然会执行并显示消息“非常好” 我点击了x按钮而不是OK按钮 确切的问题是什么?如果您使用默认的显示(“某些文本”)方法,或者只为其他方法的重写指定一个按钮,您将始终获得相同的“确定”结果。因此,无论您以何种方式关闭“OK”消息框(按钮、“ESC”或“X”),您都会得到OK,您的if条件将得到满足 要启用其他选项,您应指定多按钮值的启用日期: 将为您提供对话框结果。确定和对话框结果。取消结果。显示整个代码。“我没有看到任何事件。@安德鲁对不起,伙计,也许我输入的

问题是,即使我没有单击OK按钮,它仍然会执行并显示消息“非常好” 我点击了x按钮而不是OK按钮
确切的问题是什么?

如果您使用默认的
显示(“某些文本”)
方法,或者只为其他方法的重写指定一个按钮,您将始终获得相同的“确定”结果。因此,无论您以何种方式关闭“OK”消息框(按钮、“ESC”或“X”),您都会得到
OK
,您的
if
条件将得到满足

要启用其他选项,您应指定多按钮值的启用日期:


将为您提供
对话框结果。确定
对话框结果。取消
结果。

显示整个代码。“我没有看到任何事件。@安德鲁对不起,伙计,也许我输入的不正确。即使我没有点击OK,仍然会显示“非常好”的信息。我相信这是必须的,因为你只使用OK选项。因此,即使您通过X关闭msgbox,它仍将返回ok。尝试使用“确定/取消”进行测试。@gsharp谢谢,它正在工作。。所以MessageBoxButtons.OK是useless@SonGozita不,这不是无用的。它指示messagebox仅显示OK。非常感谢。MessageBoxButtons.OK按钮无效
int NumberOfStorey = 5;

private void HidingFirstQuestions()
{
     DialogResult dialogResult = MessageBox.Show("You Select " + NumberOfStorey + " Storey!", "Selection", MessageBoxButtons.OK);

     if (dialogResult == DialogResult.OK)
     {
         MessageBox.Show("Very Good");
     }
}
DialogResult dialogResult = 
       MessageBox.Show("You Select " + NumberOfStorey + " Storey!", 
       "Selection", MessageBoxButtons.OKCancel);