MessageBox.Show 在任务栏上显示的风格
-
19-08-2019 - |
题
有没有办法调用出现在任务栏中的MessageBox.Show?
当然,最好只是创建一个自定义表单并显示它,但作为一个懒惰的程序员,我想避免重做通过良好的老式 MessageBox.Show 调用获得的默认错误和警报通知图标。
解决方案
尝试使用 消息框选项 枚举:
MessageBox.Show("Test", "Test", MessageBoxButtons.OK, MessageBoxIcon.Information,
MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
笔记: 使用此方法会产生一些多线程副作用,请参阅文章 如何从守护程序显示用户界面.
其他提示
实现一个IWin32Window,返回句柄作为IntPtr.Zero(台式机),然后与该窗口作为父显示消息框。
private static Image GetImage(MessageBoxIcon icon)
{
switch (icon)
{
case MessageBoxIcon.Error:
return System.Drawing.SystemIcons.Error.ToBitmap();
case MessageBoxIcon.Exclamation:
return System.Drawing.SystemIcons.Exclamation.ToBitmap();
case MessageBoxIcon.Information:
return System.Drawing.SystemIcons.Information.ToBitmap();
case MessageBoxIcon.Question:
return System.Drawing.SystemIcons.Question.ToBitmap();
}
return null;
}
不隶属于 StackOverflow