.NET:MessageBox出现在后台 [英] .NET : MessageBox appears in background

查看:96
本文介绍了.NET:MessageBox出现在后台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.

我的申请有问题.

所有MessageBox均显示在应用程序后面的背景中.消息框的窗体所有者不是TopMost.谁能想到一个解决方案,为什么会这样呢?

谢谢

Hi Guys.

I have a problem with my application.

All MessageBox are shown in background behind the application. The form owner of messagebox is not TopMost. can anyone think of a solution why this is happening?

Thanks

推荐答案

消息框出现在同一线程中所有其他内容的顶部.在其他控件后面放置一个消息框表示该消息框是在与可在其上移动的窗体不同的线程上创建的.

如果您正在执行线程处理(包括异步I/O,套接字等;后台工作程序;线程池;以及.Net 4任务),则应使用BeginInvoke(或Invoke,如果希望在消息框显示时暂停线程方法)向上)以调用UI功能,例如生成消息框.

BeginInvoke在WinForms中的任何控件上,或通过WPF中的Dispatcher进行.
Message boxes appear on top of everything else within the same thread. Getting a message box behind some other controls indicates that the message box is created on a different thread to the form which can be moved over it.

If you''re threading (including asynchronous I/O, sockets etc; background workers; thread pools; and .Net 4 Tasks), you should use BeginInvoke (or Invoke, if you want the thread method to stall while the message box is up) to call UI functionality like spawning message boxes.

BeginInvoke is on any Control in WinForms, or through the Dispatcher in WPF.


您可以尝试接受IWin32Window(对于System.Windows.Forms.MessageBox而言)或Window(以防万一)的重载. System.Windows.MessageBox).
You may try overload which accepts IWin32Window (in case of System.Windows.Forms.MessageBox) or Window (in case of System.Windows.MessageBox).


这篇关于.NET:MessageBox出现在后台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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