2012-11-16 43 views
2

我有很多像這樣的代碼,它通常工作MessageBox.Show問題

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某些原因沒有顯示。 如果我按輸入它繼續像我點擊YES; 如果我按ALT鍵,那麼MessageBox奇蹟般地出現在屏幕上。

有什麼想法? 我能做些什麼來解決這個問題?

+0

更新:在'Form'我有一個'DataGridView'和看來, 'MessageBox'問題僅在我有一些彩色行時出現,我在'RowPrePaint'事件中着色。 – Shyguy

+0

其實我已經評論過'DataRow.Cells [「cell」] .value = false;'在我的'DataGridView_RowPrePaint'中,並且所有的工作都是按照必要的。 – Shyguy

回答

2

嘗試指定消息框的所有者(據我所知應該有包含該參數的重載方法)。所有者應該是當前打開的窗口。

+0

我試過設置所有者,但沒有改變我仍然有同樣的問題。不管怎麼說,還是要謝謝你 – Shyguy

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); 
} 
} 
0

因爲在應用程序中使用某些線程MessageBox可能會出現在背景上。 所以,你也必須傳遞的MessageBox在lambda表達式螺紋類似下面

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

希望這將有助於你......