MessageBox.Show flavor that shows up on the taskbar

旧时模样 提交于 2019-12-08 06:56:38

问题


Is there a way to call MessageBox.Show that appears in the taskbar?

It would probably be best to just create a custom form and display it of course, but being a lazy programmer I want to avoid redoing the default Error and Alert notification icons you get with a good old fashioned MessageBox.Show call.


回答1:


Try using the MessageBoxOptions enum:

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

Note: There are some multi threading side effect to the usage of this, see the article How To Display A User Interface From A Daemon.




回答2:


Implement an IWin32Window, return the handle as IntPtr.Zero (desktop), then display the message box with that window as the parent.




回答3:


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


来源:https://stackoverflow.com/questions/649658/messagebox-show-flavor-that-shows-up-on-the-taskbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!