1

In the MainWindow constructor, before showing my MainWindow, I'm doing some checks that could prompt a MessageBox dialog. When this happens, an ugly Windows Default Icon is showing up in the Windows taksbar with the message box title beside.

I already set an Icon for my application in Properties -> Applicaton -> Resources -> Icon.

I tried to call InitializeComponent() before calling MessageBox.Show, but it doesn't change anything.

Once my application is fully launched (I exit the MainWindow constructor), the proper icon appears in the taskbar.

Is there a way to prevent this ugly icon from showing at all, or to replace it with my own ?

Marius Bancila
  • 16,053
  • 9
  • 49
  • 91
slaadvak
  • 4,611
  • 1
  • 24
  • 34

4 Answers4

1

This should only happens en Debug time. Try running with ctrl+f5, or excecuting the .exe file directly.

Raúl Otaño
  • 4,640
  • 3
  • 31
  • 65
1

As mentioned above, go to properties of your form, set the Icon to the one you wish ALSO go to Project > (name of project) Properties > Applications (tab) and set Icon there (at the bottom). Also you can change the icon of the messagebox with

MessageBox.Show("Foo", "Bar", MessageBoxButtons.OK, MessageBoxIcon.Warning);

Read more here

rguarascia.ts
  • 694
  • 7
  • 19
0

if you are using visual studio.....go to properties window and change the icon property

enter image description here

HackerMan
  • 904
  • 7
  • 11
0

Do not show the message box from within the constructor. At this time the object (the form) is not fully created yet.

Try the form's Load event instead.

Thomas Weller
  • 55,411
  • 20
  • 125
  • 222
  • After reading [this](http://stackoverflow.com/a/4934010/501556) I prefer to override the [OnLoad](http://msdn.microsoft.com/en-us/library/system.windows.forms.form.onload.aspx) method instead. – Sameer Singh Apr 16 '14 at 08:24