Question

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?

Was it helpful?

Solution 2

Not possible.

MessageBox functionality is given to us as is. Some items are configurable, some are not. There are alternatives on the net. Check out in CodeProject, they have a few.

OTHER TIPS

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
}

Use the MessageBoxOptions enum

MessageBoxOptions.DefaultDesktopOnly
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top