From a0d9e343e93171e20800a568d25d9783370ad71e Mon Sep 17 00:00:00 2001 From: Robin Date: Fri, 18 Sep 2015 11:45:59 +0100 Subject: [PATCH] Static message box methods Added static methods for showing specific types of message boxes more easily. --- DarkUI/Forms/DarkMessageBox.cs | 29 +++++++++++++++++++++++++++++ Example/Forms/MainForm.cs | 19 ++++++++----------- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/DarkUI/Forms/DarkMessageBox.cs b/DarkUI/Forms/DarkMessageBox.cs index 6cf7d57..30384f6 100644 --- a/DarkUI/Forms/DarkMessageBox.cs +++ b/DarkUI/Forms/DarkMessageBox.cs @@ -1,6 +1,7 @@ using System; using System.ComponentModel; using System.Drawing; +using System.Windows.Forms; namespace DarkUI { @@ -66,6 +67,34 @@ namespace DarkUI #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 private void SetIcon(DarkMessageBoxIcon icon) diff --git a/Example/Forms/MainForm.cs b/Example/Forms/MainForm.cs index 8f9f014..99360f1 100644 --- a/Example/Forms/MainForm.cs +++ b/Example/Forms/MainForm.cs @@ -8,18 +8,15 @@ namespace Example { InitializeComponent(); - btnDialog.Click += delegate { - var msgBox = new DarkMessageBox("This is small", - "Dark UI Example", DarkMessageBoxIcon.Information, DarkDialogButton.AbortRetryIgnore); - msgBox.ShowDialog(); - }; + btnDialog.Click += delegate + { + DarkMessageBox.ShowError("This is an error", "Dark UI - Example"); + }; - 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); - msgBox.MaximumWidth = 350; - msgBox.ShowDialog(); - }; + btnMessageBox.Click += delegate + { + 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"); + }; } } }