Static message box methods

Added static methods for showing specific types of message boxes more
easily.
This commit is contained in:
Robin 2015-09-18 11:45:59 +01:00
parent 27a5ad0c6e
commit a0d9e343e9
2 changed files with 37 additions and 11 deletions

View File

@ -1,6 +1,7 @@
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using System.Drawing; using System.Drawing;
using System.Windows.Forms;
namespace DarkUI namespace DarkUI
{ {
@ -66,6 +67,34 @@ namespace DarkUI
#endregion #endregion
#region Static Method Region
public static DialogResult ShowInformation(string message, string caption, DarkDialogButton buttons = DarkDialogButton.Ok)
{
return ShowDialog(message, caption, DarkMessageBoxIcon.Information, buttons);
}
public static DialogResult ShowWarning(string message, string caption, DarkDialogButton buttons = DarkDialogButton.Ok)
{
return ShowDialog(message, caption, DarkMessageBoxIcon.Warning, buttons);
}
public static DialogResult ShowError(string message, string caption, DarkDialogButton buttons = DarkDialogButton.Ok)
{
return ShowDialog(message, caption, DarkMessageBoxIcon.Error, buttons);
}
private static DialogResult ShowDialog(string message, string caption, DarkMessageBoxIcon icon, DarkDialogButton buttons)
{
using (var dlg = new DarkMessageBox(message, caption, icon, buttons))
{
var result = dlg.ShowDialog();
return result;
}
}
#endregion
#region Method Region #region Method Region
private void SetIcon(DarkMessageBoxIcon icon) private void SetIcon(DarkMessageBoxIcon icon)

View File

@ -8,18 +8,15 @@ namespace Example
{ {
InitializeComponent(); InitializeComponent();
btnDialog.Click += delegate { btnDialog.Click += delegate
var msgBox = new DarkMessageBox("This is small", {
"Dark UI Example", DarkMessageBoxIcon.Information, DarkDialogButton.AbortRetryIgnore); DarkMessageBox.ShowError("This is an error", "Dark UI - Example");
msgBox.ShowDialog(); };
};
btnMessageBox.Click += delegate { btnMessageBox.Click += delegate
var msgBox = new DarkMessageBox("This is a test of the dark message box. It's cool, isn't it? You can have really quite a lot of text in here and the message box will size itself appropriately. I dislike how the default .NET message box handled this, so hopefully this will be a better option for you. :)", {
"Dark UI Example", DarkMessageBoxIcon.Information, DarkDialogButton.AbortRetryIgnore); DarkMessageBox.ShowInformation("This is some information, except it is much bigger, so there we go. I wonder how this is going to go. I hope it resizes properly. It probably will.", "Dark UI - Example");
msgBox.MaximumWidth = 350; };
msgBox.ShowDialog();
};
} }
} }
} }