2

我有很多这样的代码,它通常可以工作

private void button_Click(object sender, EventArgs e)
{
    try
    {
        DialogResult result;
        result = MessageBox.Show( "Questa operazione potrebbe richiedere alcuni minuti,\r\nsei sicuro di voler continuare?", "Attenzione", MessageBoxButtons.YesNo, MessageBoxIcon.Warning );
        if ( result == System.Windows.Forms.DialogResult.Yes )
        {
            DoSomething();
        }
        else
        {
            DoSomethingElse();
        }
    }
    Catch (Exception ex)
    {
        LogExceptio(ex);
    }
} 

但由于某种原因,特定Windows FormMessageBox没有显示。如果我按下Enter它,就像我点击“是”一样继续;如果我按下ALT键,MessageBox 会神奇地出现在屏幕上。

任何想法?我能做些什么来解决这个问题?

4

3 回答 3

2

尝试为消息框指定所有者(据我所知,应该有包含该参数的重载方法)。所有者应该是当前打开的窗口。

于 2012-11-16T12:06:45.947 回答
0

我通过设置 DataGrid.visible = false 来解决这个问题。

private void button_Click(object sender, EventArgs e)
{
try
{
    DialogResult result;
    DataGrid.visible=false;
    result = MessageBox.Show( "Questa operazione potrebbe richiedere alcuni minuti,\r\nsei sicuro di voler continuare?", "Attenzione", MessageBoxButtons.YesNo, MessageBoxIcon.Warning );
    if ( result == System.Windows.Forms.DialogResult.Yes )
    {
        DoSomething();
    }
    else
    {
        DoSomethingElse();
    }
}
DataGrid.visible=true;
Catch (Exception ex)
{
    LogExceptio(ex);
}
} 
于 2016-09-26T14:53:44.423 回答
0

因为在你的应用程序中使用了一些线程 MessageBox 可能会出现在背景上。因此,您还必须在 lambda 表达式线程中传递 MessageBox,如下所述

new Thread(() => 
 {
    MessageBox.Show("Your Text");
 }).Start();

希望它会帮助你...

于 2017-11-15T07:35:50.020 回答