Button Parameters in Windows Forms MessageBox

18 Nov 20187 minutes to read

Show function helps to display a MessageBoxAdv. This section explains regarding the parameters available in Show function.

Caption bar text

The text to display in the caption bar of the MessageBox.

Text

Represents the text which need to be displayed in the MessageBox.

Buttons

Provides various button combination like Ok, OkCancel, YesNo, YesNoCancel, RetryCancel and much more. By default, it shows only Ok button. MessageBoxButtons enumeration helps to set various button combination in MessageBoxAdv. Some of the available default buttons are as follows:

  • Ok
  • OkCancel
  • YesNo
  • YesNoCancel
  • RetryCancel
  • AbortRetryIgnore

Ok

This option helps to show the MessageBoxAdv with Ok button.

//MessageBox with Ok Button

MessageBoxAdv.Show(this, "Save changes?", "File Modified", MessageBoxButtons.OK, MessageBoxIcon.Question);
'MessageBox with Ok Button

MessageBoxAdv.Show(Me, "Save changes?", "File Modified", MessageBoxButtons.OK, MessageBoxIcon.Question)

WindowsForms MessageBox with Ok button

Ok Cancel

This option helps to show the MessageBoxAdv with combination of Ok and Cancel buttons.

//MessageBox with combination of Ok and Cancel buttons.

MessageBoxAdv.Show(this, "Save changes?", "File Modified", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
'MessageBox with combination of Ok and Cancel buttons.

MessageBoxAdv.Show(Me, "Save changes?", "File Modified", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)

WindowsForms MessageBox with Ok and Cancel buttons

Yes No

This option helps to show the MessageBoxAdv with combination of Yes and No buttons.

//MessageBox with combination of Yes and No buttons.

MessageBoxAdv.Show(this, "Save changes?", "File Modified", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
'MessageBox with combination of Yes And No buttons.

MessageBoxAdv.Show(Me, "Save changes?", "File Modified", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

WindowsForms MessageBox With Yes and No buttons

Yes No Cancel

This option helps to show the MessageBoxAdv with combination of Yes, No, and Cancel buttons.

//MessageBox with combination of Yes,No and Cancel buttons.

MessageBoxAdv.Show(this, "Save changes?", "File Modified", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
'MessageBox with combination of Yes,No And Cancel buttons.

MessageBoxAdv.Show(Me, "Save changes?", "File Modified", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)

WindowsForms MessageBox with Yes No Cancel buttons

Retry Cancel

This option helps to show the MessageBoxAdv with combination of Retry and Cancel buttons.

//MessageBox with combination of Retry and Cancel buttons.

MessageBoxAdv.Show(this, "Save changes?", "File Modified", MessageBoxButtons.RetryCancel, MessageBoxIcon.Question);
'MessageBox with combination of Retry And Cancel buttons.

MessageBoxAdv.Show(Me, "Save changes?", "File Modified", MessageBoxButtons.RetryCancel, MessageBoxIcon.Question)

WindowsForms MessageBoxAdv with Retry and Cancel buttons

Abort Retry Ignore

This option helps to show the MessageBoxAdv with combination of Abort, Retry, and Ignore buttons.

//MessageBox with combination of Abort,Retry and Ignore buttons.

MessageBoxAdv.Show(this, "Save changes?", "File Modified", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Question);
'MessageBox with combination of Abort,Retry And Ignore buttons.

MessageBoxAdv.Show(Me, "Save changes?", "File Modified", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Question)

WindowsForms MessageBoxAdv with Abort Retry Ignore buttons

Icon

Supports to display wide variety of built-in icons and also empowered with loading custom icons. The default icons can be displayed in MessageBox by using MessageBoxIcon Enum and it is listed as follows:

  • Asterisk
  • Error
  • Exclamation
  • Hand
  • Information
  • None
  • Question
  • Stop
  • Warning

The following code example illustrates adding Exclamation icon in MessageBox.

//Icon Support

MessageBoxAdv.Show(this, "Save changes?", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
'Icon Support

MessageBoxAdv.Show(Me, "Save changes?", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation)

WindowsForms MessageBox Icon support

The following code example illustrates adding custom icons in MessageBoxAdv.

//Icon Support

MessageBoxAdv.Show(this, "Save changes?", "Warning", MessageBoxButtons.OKCancel, image, new Size(50,50));
'Icon Support

MessageBoxAdv.Show(Me, "Save changes?", "Warning", MessageBoxButtons.OKCancel, image, New Size(50,50))

WindowsForms MessageBox Custom Icon support

Right to left support

The MessageBox elements can be aligned in right-to-left layout. It is laid out from the right to left when RightToLeft property is set to true. Its default value is false.

MessageBoxAdv.RightToLeft = RightToLeft.Yes;

MessageBoxAdv.Show(this,"Save changes?", "File Modified", MessageBoxButtons.YesNo,MessageBoxIcon.Question);
MessageBoxAdv.RightToLeft = RightToLeft.Yes

MessageBoxAdv.Show(Me,"Save changes?", "File Modified", MessageBoxButtons.YesNo,MessageBoxIcon.Question)

WindowsForms MessageBox Right to left support

Details view

This pane helps to view the detail message about the text shown in the MessageBox. It also provide options to show / hide the detail pane.

MessageBoxAdv.Show(this, "Save changes?", "Warning", MessageBoxButtons.OKCancel, image, new Size(50, 50), "Do you want to save your changes to respective file location?");
MessageBoxAdv.Show(Me, "Save changes?", "Warning", MessageBoxButtons.OKCancel, image, New Size(50, 50), "Do you want to save your changes to respective file location?")

Eg: Detail view

WindowsForms MessageBox Details view support

Eg: Collapsed view

WindowsForms MessageBox Collapsed view support

Resizing support

The MessageBox allows you to adjust the size of the control at run time by dragging the gripper at bottom right. It can be achieved by using the CanResize property. The default value is false.

MessageBoxAdv.CanResize = true;
MessageBoxAdv.CanResize = True

WindowsForms MessageBox Resizing support

View sample in GitHub