我有一些弹出消息框的代码:
MessageBox.Show(this,
"You have not inputted a username or password. Would you like to configure your settings now?",
"Settings Needed",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
我的问题是当它弹出时我的应用程序通常最小化到托盘。因此,消息框不会出现在最前面,也不会出现在开始栏上。查看它的唯一方法是通过 alt-tabbing。
这是将我的应用程序(父应用程序)最小化到托盘的代码:
if (FormWindowState.Minimized == WindowState)
{
Hide();
}
最佳答案
还有一个额外的标志,您可以将其指定为标准 Windows MessageBox
function 的选项。未在 WinForms 包装器中公开。
您正在寻找的是 MB_TOPMOST
,它确保消息框显示为桌面上所有其他内容的最顶层窗口。只需修改您的代码,如下所示:
MessageBox.Show(this,
"You have not inputted a username or password. Would you like to configure your settings now?",
"Settings Needed",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1, // specify "Yes" as the default
(MessageBoxOptions)0x40000); // specify MB_TOPMOST
关于当应用程序最小化到托盘时,C# MessageBox 显示在前面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4834819/