Windows Forms: Metro Message Box in C#
By FoxLearn 3/22/2020 7:06:27 PM 23.81K
To create a metro or modern ui style windows application in c#, you can use the metroframework library.
First off, you need to install the metro framework to your projecy by right-clicking on your project, then select Manage NuGet Packages -> Search metro framework -> Install
Dragging the MetroTile from the visual studio toolbox to your winform, then you can design a simple dashboard as shown below.
If you haven't got the metro framework toolbox, you can view the post how to download and install metro framework to visual studio toolbox
To create a metro form, you should change inheritance from Form to the MetroForm, then you can handle your form as the following c# code.
using System; using System.Windows.Forms; namespace MetroMessageBoxDemo { public partial class Form1 : MetroFramework.Forms.MetroForm { public Form1() { InitializeComponent(); } //OK message box private void metroTile1_Click(object sender, EventArgs e) { MetroFramework.MetroMessageBox.Show(this, "OK", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } //Yes/No message box private void metroTile3_Click(object sender, EventArgs e) { if (MetroFramework.MetroMessageBox.Show(this, "Yes/No", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { //Do something } } //YesNo/Cancel message box private void metroTile2_Click(object sender, EventArgs e) { if (MetroFramework.MetroMessageBox.Show(this, "YesNo/Cancel", "Message", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes) { //Do something } } //Error message box private void metroTile4_Click(object sender, EventArgs e) { MetroFramework.MetroMessageBox.Show(this, "Error", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } //Warning message box private void metroTile5_Click(object sender, EventArgs e) { MetroFramework.MetroMessageBox.Show(this, "Warning", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning); } //Hand message box private void metroTile6_Click(object sender, EventArgs e) { MetroFramework.MetroMessageBox.Show(this, "Hand", "Message", MessageBoxButtons.OK, MessageBoxIcon.Hand); } //Stop message box private void metroTile7_Click(object sender, EventArgs e) { MetroFramework.MetroMessageBox.Show(this, "Stop", "Message", MessageBoxButtons.OKCancel, MessageBoxIcon.Stop); } //OK message box private void metroTile8_Click(object sender, EventArgs e) { MetroFramework.MetroMessageBox.Show(this, "None"); } } }
Through the c# example above, you've learned how to use metro ui framework to create Metro MessageBox types in c# .net windows forms application.
VIDEO TUTORIAL
- Windows Forms: Metro TextBox in C#
- Download and Install Metro Framework
- Windows Forms: Metro GridView in C#
- Windows Forms: Modern UI Login Form in C#
- Windows Forms: Metro ListView in C#
- Windows Forms: How to use WinForms Modern UI Metro Framework in C#
- Windows Forms: Modern UI Metro Framework Windows 8 UI in C#
- Windows Forms: How to use Winforms Modern UI Metro Framework in C#