C# message box buttons – (button arguments)


The message box in C# can have different property values for the buttons to be displayed.  The dialog buttons are specified in the third argument for the MessageBox.Show( ) method.

Example:  MessageBox.Show(message, “This text is at the top of the message box”, MessageBoxButtons.OK);

MessageBoxButtons.AbortRetryIgnore
MessageBoxButtons.OK
MessageBoxButtons.OKCancel
MessageBoxButtons.RetryCancel
MessageBoxButtons.YesNo
MessageBoxButtons.YesNoCancel

In the fourth argument you can specify the type of icon used

MessageBoxIcon.Asterisk
MessageBoxIcon.Error
MessageBoxIcon.Exclamation
MessageBoxIcon.Hand
MessageBoxIcon.Information
MessageBoxIcon.Question
MessageBoxIcon.Stop
MessageBoxIcon.Warning

Intellisense in VS should tell you but just in case you’re wondering, here they are and an example of how to use it.  Message boxes can be used in Windows forms and Console applications as long as you add a reference to the Systems.Windows.Forms.dll

2 Comments

Filed under Computer - Technical

2 responses to “C# message box buttons – (button arguments)

  1. eanirudh

    hi Oscar, great post but it does not work on asp.net(i.e. web application). This is for only window application.
    Is there any feature for message box in web applications is provided by the visual studio?
    Please let me know the answer.

    Thanks and Take care

  2. For ASP.NET you’ll need to reference the Validation Summary class. At w3schools, they give an example using a validation control that will alert you when fields are left empty.

    http://www.w3schools.com/aspnet/showasp.asp?filename=demo_validationsum2

    I hope this is what you are looking for.

Comment on this

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s