问题描述
我想在带有OK按钮的while循环中使用MessageBox。我希望MessageBox一直显示,直到用户按下“确定”按钮为止。如果我使用此代码,则会显示该框,并且该框会一直等到用户按下按钮,并且不会继续进行下一个迭代。
DialogResult dialogResult;
stopiteration = false;
While(!stopiteration)
{
nIteration += 1;
dialogResult = MessageBox.Show(string.Format("Iteration: {0}",nIteration),"Iterations",MessageBoxButtons.OK);
if (dialogResult == DialogResult.OK)
{
stopiteration = true;
}
}
public partial class RunMessageBox : Form
{
public RunMessageBox()
{
InitializeComponent();
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
}
}
RunMessageBox runMessageBox = new RunMessageBox();
runMessageBox.Show(); // If I use DialogShow instead the same problem as MessageBox happens
While(!stopiteration)
{
nIteration += 1;
runMessageBox.labelIteration.Text = string.Format("Iteration: {0}",nIteration);
if (runMessageBox.checkBoxstopiteration.Checked)
{
stopiteration = true;
}
}
这次,直到最后一次迭代(代码包括最大迭代检查),才会显示要停止的标签和复选框。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)