Moj*_*ojo 4 c# exception messagebox winforms
当我尝试启动一个消息框(通常是通知异常,但我尝试从表单中启动一个消息框)时,程序似乎停止运行,除了关闭它之外我无法单击任何内容,但它必须完成从视觉工作室窗口。
我已将问题范围缩小到与 pictureBox1_paint 事件处理程序有关,因为当我删除此代码时,消息框开始再次出现。这是相关代码:
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
using (Pen pen = new Pen(Color.Black, 1))
{
e.Graphics.DrawRectangle(pen, mRect);
}
pictureBox1.Invalidate();
}
Run Code Online (Sandbox Code Playgroud)
调用堆栈显示它位于某些外部代码上,在我看来,它在展开时将消息框“绘制”到屏幕上,但似乎被某些东西阻碍了?如果程序暂停,它会显示要执行的下一行是当它从正在执行的操作返回时,示例如下:
private void button2_Click(object sender, EventArgs e)
{
if (GlobalPlot != null)
{
resize = ExpandToBound(GlobalPlot.Size, pictureBox1.Size);
}
else return;
try
{
PlotPixel(resize);
}
catch (System.ArgumentOutOfRangeException index)
{
//this is the next line to execute:
MessageBox.Show(index.Message,"Exception",MessageBoxButtons.OK);
return;
}
}
Run Code Online (Sandbox Code Playgroud)
不太确定发生了什么,但非常感谢任何帮助,谢谢。
小智 6
因为这是该主题中浏览次数最多的问题,所以这是一个真正的工作解决方案。只需填写所有 MessageBox 参数,如 MessageBox.Show(index.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);