MessageBox.Show风格显示在任务栏上

时间:2009-03-16 08:45:30

标签: .net taskbar messagebox

有没有办法调用任务栏中出现的MessageBox.Show?

最好只创建一个自定义表单并显示它当然,但作为一个懒惰的程序员我想避免重做你用一个老式的MessageBox.Show调用得到的默认错误和警报通知图标。 / p>

3 个答案:

答案 0 :(得分:3)

尝试使用MessageBoxOptions枚举:

MessageBox.Show("Test", "Test", MessageBoxButtons.OK, MessageBoxIcon.Information,
    MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);

注意:使用此功能会产生多线程影响,请参阅文章How To Display A User Interface From A Daemon

答案 1 :(得分:1)

实现IWin32Window,将句柄作为IntPtr.Zero(桌面)返回,然后显示该窗口作为父窗口的消息框。

答案 2 :(得分:1)

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;
}