11

in C# winforms when we display a message box it has no title in the title bar and no title in its button that is in the task bar.

What if i want to set title and icon for a message box.

one option is that create a form that appears and behaves like a message box and i show and hide it when i want. yes that can be done but i want to modify the "MessageBox"

Moon
  • 19,518
  • 56
  • 138
  • 200

4 Answers4

38

Use a MessageBox.Show overload such as:

public static DialogResult Show(
    string text,
    string caption,
    MessageBoxButtons buttons,
    MessageBoxIcon icon
)

passing your title bar text in caption and your icon in icon e.g.

MessageBox.Show("Oh noes!", "My Application", MessageBoxButtons.OK, MessageBoxIcon.Error);
itowlson
  • 73,686
  • 17
  • 161
  • 157
  • 1
    That's the one, beat me to it – colithium Aug 25 '09 at 07:32
  • 1
    The problem is that when minimized, the icon is not showed on the taskbar, I think this is what he wants... – Svetlozar Angelov Aug 25 '09 at 07:33
  • Hmm, if he wants a message box that appears on the taskbar, has a window icon and can be minimised (or allows the underlying window to be minimised) then he will need to write a custom form. You can't do all that with MessageBox -- it's pretty primitive! – itowlson Aug 25 '09 at 07:42
  • @itowlson: Is there a way I can skip the MessageBoxButtons property. Actually, i do not want to show the OK or OK/Cancel or any of the property of the button. I can't override the method without skipping the property? – Ankur Sharma May 27 '13 at 12:34
  • @AnkurSharma: No, there's no overload of MessageBox.Show that allows you to set the icon without specifying which button(s) to show. And there is no way to not show any buttons at all - the overloads with no MessageBoxButtons argument internally pass MessageBoxButtons.OK. If you want to show a message box with no buttons, you'll have to create a custom form. – itowlson May 27 '13 at 23:06
1

There is an overloaded version of show message box that will accept a title string and let you specify the icon and number/type of buttons.

colithium
  • 10,269
  • 5
  • 42
  • 57
1

The MessageBox.Show method has a bunch of overrides that allow you to set the properties of the pop-up.

http://msdn.microsoft.com/en-us/library/system.windows.forms.messagebox.show%28VS.71%29.aspx

Andy White
  • 86,444
  • 48
  • 176
  • 211
0

One short 2 line answer , your name space using System.Windows.Forms; will already be there , in message box you need to pass all parameters , it might not work if you uses only icon

using System.Windows.Forms;              
MessageBox.Show("yourmessage","yourTitle",MessageBoxButtons.OK,MessageBoxIcon.Error);
Hietsh Kumar
  • 1,197
  • 9
  • 17