Getting Started with Windows Forms MessageBox

18 Nov 20182 minutes to read

This section explains how to configure MessageBoxAdv control in a Windows Forms application.

Assembly deployment

Refer control dependencies section to get the list of assemblies or NuGet package needs to be added as reference to use the control in any application.

Please find more details regarding how to install the nuget packages in windows form application in the below link:

How to install nuget packages

Creating simple application with MessageBox

You can create the Windows Forms application with MessageBox as follows:

  1. Creating the project
  2. Configure MessageBox

Creating the project

Create a new Windows Forms project in the Visual Studio to display the MessageBoxAdv.

Configure MessageBox

To add control manually in C#, follow the given steps:

Step1: Add the following required assembly references to the project:

  • Syncfusion.Shared.Base.dll

Step2: Include the namespaces Syncfusion.Windows.Forms.

using Syncfusion.Windows.Forms;
Imports Syncfusion.Windows.Forms

Step3: Displays the MessageBoxAdv by using Show function.

// Display the MessageBox using [Show](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.MessageBoxAdv.html#Syncfusion_Windows_Forms_MessageBoxAdv_Show_System_String_) function.

MessageBoxAdv.MessageBoxStyle = MessageBoxAdv.Style.Metro;

MessageBoxAdv.Show(this,"Save changes?", "File Modified", MessageBoxButtons.YesNo,MessageBoxIcon.Question);
' Display the MessageBox using [Show](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.MessageBoxAdv.html#Syncfusion_Windows_Forms_MessageBoxAdv_Show_System_String_) function.

MessageBoxAdv.MessageBoxStyle = MessageBoxAdv.Style.Metro

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

Windows Forms MessageBox

Appearance of MessageBox

The appearance of the MessageBox can be customized by using the following properties of the MetroStyleColorTable.

  • AbortButtonBackColor
  • CancelButtonBackColor
  • IgnoreButtonBackColor
  • NoButtonBackColor
  • OKButtonBackColor
  • RetryButtonBackColor
  • YesButtonBackColor
  • CaptionBarColor
  • CaptionForeColor
  • ForeColor
  • BackColor
  • BorderColor
//MetroColor table for MessageBox
MetroStyleColorTable metroColorTable = new MetroStyleColorTable();
//Sets the NoButton backColor
metroColorTable.NoButtonBackColor = Color.Red;
//Sets the YesButton backColor
metroColorTable.YesButtonBackColor = Color.SkyBlue;
//Sets the OK button backcolor
metroColorTable.OKButtonBackColor = Color.Green;
//Applies the MetroStyleColorTable to MessageBoxAdv
MessageBoxAdv.MetroColorTable = metroColorTable;
//Sets the MessageBoxStyle as Metro
MessageBoxAdv.MessageBoxStyle = MessageBoxAdv.Style.Metro;
'MetroColor table for MessageBox
Dim metroColorTable As New MetroStyleColorTable()
'Sets the NoButton backColor
metroColorTable.NoButtonBackColor = Color.Red
'Sets the YesButton backColor
metroColorTable.YesButtonBackColor = Color.SkyBlue
'Sets the OK button backcolor
metroColorTable.OKButtonBackColor = Color.Green
'Applies the MetroStyleColorTable to MessageBoxAdv
MessageBoxAdv.MetroColorTable = metroColorTable
'Sets the MessageBoxStyle as Metro
MessageBoxAdv.MessageBoxStyle = MessageBoxAdv.Style.Metro

WindowsForms MessageBox Appearance