简体   繁体   English

MessageBox.Show 问题

[英]MessageBox.Show issue

I have a lot of code like this and it usually works我有很多这样的代码,它通常有效

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

but for some reason on a specific Windows Form the MessageBox is not showing.但出于某种原因,在特定的Windows FormMessageBox没有显示。 If I press Enter it proceed like I have made a click on YES;如果我按Enter它会继续,就像我点击了 YES 一样; If I press the ALT key the MessageBox magically appear on the screen.如果我按下ALT键,MessageBox 会神奇地出现在屏幕上。

Any idea?任何的想法? What can I do to solve this issue?我能做些什么来解决这个问题?

Try to specify owner for the message box (as far as I remember there should be overloaded method containing that argument).尝试为消息框指定所有者(据我所知应该有包含该参数的重载方法)。 Owner should be current opened window.所有者应该是当前打开的窗口。

I solve this problem by setting DataGrid.visible = false.我通过设置 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);
}
} 

Because Of using some Threads in your application MessageBox May appear on background.因为在你的应用程序中使用了一些线程 MessageBox 可能会出现在后台。 So, You have to Pass MessageBox also in lambda expression Thread Like Below mentioned因此,您还必须在 lambda 表达式 Thread 中传递 MessageBox 如下所述

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

Hope It Will Help You...希望它会帮助你...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM