为什么MessageBox不是TopMost? [英] Why isn't MessageBox TopMost?
问题描述
我最近发现默认情况下,默认情况下,MessageBox并不是最常见的表单,我想知道是否有人知道您不希望在其他窗口上方显示MessageBox的情况?
I recently found out that by default MessageBoxes were not the top most form when displayed by default and I was wondering if anyone knew any circumstances when you wouldn't want the messagebox to be shown on top of other windows?
当我在加载应用程序时开始显示初始屏幕时,我发现了问题,看起来我的程序仍在运行,但是初始屏幕后面有一个MessageBox
,正在等待输入.在与调用消息框的线程不同的线程上显示,因此我想这就是为什么它没有出现在启动画面上方的原因;但这仍然不能解释为什么MessageBox在默认情况下没有MB_TOPMOST
标志?
I found the issue when I started to show splash screens whilst loading an application, and it looked like my program was still running but there was a MessageBox
behind the splash screen that was waiting for input.. The splash screen was shown on a different thread to the thread that called the messagebox so I imagine this is why it didn't appear above the splash; but this still doesn't explain why MessageBox doesn't have the MB_TOPMOST
flag by default?
修改
为了更好地说明: 最后,我必须做类似的事情才能制作一个消息框,代码与从内存中写入的代码并不完全正确.
To better clarify: in the end I had to do something similar to this in the end to make a messagebox, code isn't exactly correct as wrote from memory)
[DllImport("User32.dll")]
private int extern MessageBox(windowhandle, message, caption, flag);
public static void MessageBox(windowhandle, string message, string caption)
{
MessageBox(windowhandle, message,caption, MB_TOPMOST);
}
推荐答案
在应用程序的最上方显示消息框
To show the MessageBox on top-most of all for the application
代码
//Should be MessageBox.Show() below
MessageBox.Show(this, "My top most message");
默认情况下不为MB_TOPMOST
的原因
Reason for not being MB_TOPMOST
by default
如果将MB_TOPMOST设置为默认值,则
MessageBox
将以系统模式"模式显示,它将恰好位于该表格的顶部,并且副作用是系统模式"模式将导致MessageBox
阻止窗口,直到消息正常消失为止,它将是应用程序模式"模式.
If MB_TOPMOST will be default then the
MessageBox
will show up in a 'system modal' mode and it will be exactly on top on that form and side effects are that the 'system modal' mode will cause theMessageBox
to Block the windows until the message is dismissed normally it will be 'application modal' mode.
参考链接
- MSDN forum - How to display a MessageBox as topmost window
- SO - C# MessageBox To Front When App is Minimized To Tray
这篇关于为什么MessageBox不是TopMost?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!