Is it possible to call the static MessageBox
class Show()
method in a way that it does not have a taskbar icon, or has a custom image? I'm trying to find an alternative to constructing custom MessageBox
class.
Thanks.
I tried to the the DefaultDesktopOnly
option in the following way:
if (MessageBox.Show("Are you sure you would like to do something?", "Title", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly) == DialogResult.Yes)
{
//Do stuff
}
However there was still an icon in the taskbar and also the main form started crashing as well. I'm in Win7 if it matters. Are there stability issues with DefaultDesktopOnly
?
You need to give the MessageBox
an owner window that has (or not) an icon of itself for the dialog to NOT to show on its own. If you call the MessageBox
from an open form, you can pass the form as the first parameter to make it its owner:
// Assume "this" is a form, not valid from any other class
if (MessageBox.Show(this, "Are you sure you would like to do something?", "Title", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly) == DialogResult.Yes)
{
//Do stuff
}
But if your program has no other GUI visible at the moment, you may simply create a dummy form just for the sake of providing it an owner, like so:
// A new, invisible form is created as the MessageBox owner, this prevents it from appearing in the taskbar
if (MessageBox.Show(new Form(), "Are you sure you would like to do something?", "Title", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly) == DialogResult.Yes)
{
//Do stuff
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With