Reputation: 101176
How do I specify which icon a MessageBox
should use in the taskbar? There are no MessageBox.Show
overloads which let me select a taskbar icon, only an icon to use in the actual form.
Upvotes: 9
Views: 6087
Reputation: 326
To be able to show an Icon for a MessageBox
at Task bar, I found a way to avoid creating custom form, but somehow we will create a dummy form (or you can change it into anonymous form):
using (Form dummy = new Form() {
Icon = Properties.Resources.ico_Main_Logo
, TopMost = true
, FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
, Size = new System.Drawing.Size(0,0)
, BackColor = Color.White
, TransparencyKey = Color.White
})
{
dummy.Show();
MessageBox.Show(dummy, "This is a MessageBox with Icon at Taskbar and on top of all windows", "Title Text", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
With above way, these useful features will be possible:
MessageBox
at Task Bar. (I use Application Setting to load an Icon, you can do it from Disk or ...)MessageBox
window at Top of other windows. (if you do not want it then set TopMost = false
)MessageBox
Icon at Task bar. (Just initial a simple Form at usage and remove dummy.Show();
line.)Or just initial anonymous Form like this to hide MessageBox
Icon from Task bar:
MessageBox.Show(new Form(), "This is a MessageBox Hide it from Taskbar", "Title Text", MessageBoxButtons.OK, MessageBoxIcon.Information);
Anyway, I just want share my new founds so it may help others too. Thank you.
This works fine, But I do not know why even when I set Size
of Form to (0, 0)
it still have a size of 131x37!!! But because the Form set as Transparency, It will be not visible and mouse pointer will click trough.
Upvotes: 3
Reputation: 3720
I don't think it's possible to change the taskbar icon; your only option would be to make your own MessageBox.
Upvotes: 7
Reputation: 210755
Short answer: You can't.
Short answer #2: You need to make your own form for this, and display it manually.
Upvotes: 3