消息框,允许一个进程自动继续 [英] MessageBox that allows a process to continue automatically

查看:126
本文介绍了消息框,允许一个进程自动继续的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个消息框来显示和程序只是继续,而不是等我单击【确定】此消息框。能不能做到?

 其他
{
    //调试或消息框失败行
    的MessageBox.show(列数:+ _columns.Length.ToString()+行:+线[I]);

}
 

解决方案

首先,正确的解决办法是用一个普通的窗口更换消息框(或表单,如果您使用的WinForms)。这将是相当简单。示例(WPF)

 <窗​​口x:类=本地:mywindow的...>
    <电网>
        < TextBlock中的Horizo​​ntalAlignment =中心VerticalAlignment =中心
                   文本={结合}/>
        <按钮的Horizo​​ntalAlignment =右VerticalAlignment =底部
                   点击=SelfClose>关闭< /按钮>
    < /网格>
< /窗>

...
类mywindow的:窗口
{
    公共mywindow的(字符串消息){this.DataContext =消息; }
    无效SelfClose(对象发件人,RoutedEventArgs E){this.Close(); }
}

...
新mywindow的(列数:+ _columns.Length.ToString()+行:+线[I])显示()。
 

如果你想快速和肮脏的解决方案,你可以调用从暴殄天物线程的消息框:

 线程t =新主题(()=>的MessageBox(lalalalala));
t.SetApartmentState(ApartmentState.STA);
t.Start();
 

(不知道 ApartmentState.STA 实际需要)

I would like a message box to be displayed and the program to just continue and not wait for me to click ok on this message box. Can it be done ?

else
{
    // Debug or messagebox the line that fails
    MessageBox.Show("Cols:" + _columns.Length.ToString() + " Line: " + lines[i]);

}

解决方案

First, the correct solution would be to replace the messagebox with a plain window (or form, if you are using winforms). That would be quite simple. Example (WPF)

<Window x:Class="local:MyWindow" ...>
    <Grid>
        <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center"
                   Text="{Binding}" />
        <Button HorizontalAlignment="Right" VerticalAlignment="Bottom"
                   Click="SelfClose">Close</Button>
    </Grid>
</Window>

...
class MyWindow : Window
{
    public MyWindow(string message) { this.DataContext = message; }
    void SelfClose(object sender, RoutedEventArgs e) { this.Close(); }
}

...
new MyWindow("Cols:" + _columns.Length.ToString() + " Line: " + lines[i]).Show();

If you want a quick-and-dirty solution, you can just call the messagebox from a throwaway thread:

Thread t = new Thread(() => MessageBox("lalalalala"));
t.SetApartmentState(ApartmentState.STA);
t.Start();

(not sure if ApartmentState.STA is actually needed)

这篇关于消息框,允许一个进程自动继续的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆