我正在使用以下代码显示带有ok和cancel按钮的MessageBox。当我单击任何按钮时,会再次出现相同的消息框。这段代码有什么问题吗?
string messageBoxText = "Uploading Data";
string caption = "Upload Data";
MessageBoxButton button = MessageBoxButton.OKCancel;
// Display message box
MessageBox.Show(messageBoxText, caption, button, icon);
MessageBoxResult res = MessageBox.Show(messageBoxText, caption, button, icon);
if (res == MessageBoxResult.OK)
{
count++;
}
string messageBoxText = "Uploading Data";
string caption = "Upload Data";
MessageBoxButton button = MessageBoxButton.OKCancel;
// Display message box
MessageBox.Show(messageBoxText, caption, button, icon);
MessageBoxResult res = MessageBox.Show(messageBoxText, caption, button, icon);
if (res == MessageBoxResult.OK)
{
count++;
}
答案 0 :(得分:5)
因为您要拨打MessageBox.Show
两次......
string messageBoxText = "Uploading Data";
string caption = "Upload Data";
MessageBoxButton button = MessageBoxButton.OKCancel;
// Display message box
MessageBox.Show(messageBoxText, caption, button, icon); //**Comment this line**
MessageBoxResult res = MessageBox.Show(messageBoxText, caption, button, icon);
if (res == MessageBoxResult.OK)
{
count++;
}
答案 1 :(得分:2)
您通过MessageBox.Show
呼叫消息框两次。您可能想要删除第一个
MessageBox.Show(messageBoxText, caption, button, icon);