This repository has been archived on 2022-08-05. You can view files and clone it, but cannot push or open issues or pull requests.
Cashew/cashew/MessageBox/MetroMessageBox.cs

172 lines
5.1 KiB
C#

using System;
using System.Drawing;
using System.Media;
using System.Threading;
using System.Windows.Forms;
namespace cashew.MessageBox
{
public static class MetroMessageBox
{
public static DialogResult Show(IWin32Window owner, string message)
{
return MetroMessageBox.Show(owner, message, "Notification", 211);
}
public static DialogResult Show(IWin32Window owner, string message, int height)
{
return MetroMessageBox.Show(owner, message, "Notification", height);
}
public static DialogResult Show(IWin32Window owner, string message, string title)
{
return MetroMessageBox.Show(owner, message, title, MessageBoxButtons.OK, 211);
}
public static DialogResult Show(
IWin32Window owner,
string message,
string title,
int height)
{
return MetroMessageBox.Show(owner, message, title, MessageBoxButtons.OK, height);
}
public static DialogResult Show(
IWin32Window owner,
string message,
string title,
MessageBoxButtons buttons)
{
return MetroMessageBox.Show(owner, message, title, buttons, MessageBoxIcon.None, 211);
}
public static DialogResult Show(
IWin32Window owner,
string message,
string title,
MessageBoxButtons buttons,
int height)
{
return MetroMessageBox.Show(owner, message, title, buttons, MessageBoxIcon.None, height);
}
public static DialogResult Show(
IWin32Window owner,
string message,
string title,
MessageBoxButtons buttons,
MessageBoxIcon icon)
{
return MetroMessageBox.Show(owner, message, title, buttons, icon, MessageBoxDefaultButton.Button1, 211);
}
public static DialogResult Show(
IWin32Window owner,
string message,
string title,
MessageBoxButtons buttons,
MessageBoxIcon icon,
int height)
{
return MetroMessageBox.Show(owner, message, title, buttons, icon, MessageBoxDefaultButton.Button1, height);
}
public static DialogResult Show(
IWin32Window owner,
string message,
string title,
MessageBoxButtons buttons,
MessageBoxIcon icon,
MessageBoxDefaultButton defaultbutton)
{
return MetroMessageBox.Show(owner, message, title, buttons, icon, defaultbutton, 211);
}
public static DialogResult Show(
IWin32Window owner,
string message,
string title,
MessageBoxButtons buttons,
MessageBoxIcon icon,
MessageBoxDefaultButton defaultbutton,
int height)
{
DialogResult dialogResult = DialogResult.None;
if (owner != null)
{
Form form = !(owner is Form) ? ((ContainerControl) owner).ParentForm : (Form) owner;
switch (icon)
{
case MessageBoxIcon.Hand:
SystemSounds.Hand.Play();
break;
case MessageBoxIcon.Question:
SystemSounds.Beep.Play();
break;
case MessageBoxIcon.Exclamation:
SystemSounds.Exclamation.Play();
break;
default:
SystemSounds.Asterisk.Play();
break;
}
MetroMessageBoxControl messageBoxControl = new MetroMessageBoxControl();
messageBoxControl.BackColor = form.BackColor;
messageBoxControl.Properties.Buttons = buttons;
messageBoxControl.Properties.DefaultButton = defaultbutton;
messageBoxControl.Properties.Icon = icon;
messageBoxControl.Properties.Message = message;
messageBoxControl.Properties.Title = title;
messageBoxControl.Padding = new Padding(0, 0, 0, 0);
messageBoxControl.ControlBox = false;
messageBoxControl.ShowInTaskbar = false;
messageBoxControl.TopMost = true;
messageBoxControl.Size = new Size(form.Size.Width, height);
messageBoxControl.Location = new Point(form.Location.X, form.Location.Y + (form.Height - messageBoxControl.Height) / 2);
messageBoxControl.ArrangeApperance();
Convert.ToInt32(Math.Floor((double) messageBoxControl.Size.Height * 0.28));
int num = (int) messageBoxControl.ShowDialog();
messageBoxControl.BringToFront();
messageBoxControl.SetDefaultButton();
Action<MetroMessageBoxControl> action = new Action<MetroMessageBoxControl>(MetroMessageBox.ModalState);
IAsyncResult asyncResult = action.BeginInvoke(messageBoxControl, (AsyncCallback) null, (object) action);
bool flag = false;
try
{
while (!asyncResult.IsCompleted)
{
Thread.Sleep(1);
Application.DoEvents();
}
}
catch
{
flag = true;
if (!asyncResult.IsCompleted)
{
try
{
}
catch
{
}
}
}
if (!flag)
{
dialogResult = messageBoxControl.Result;
messageBoxControl.Dispose();
}
}
return dialogResult;
}
private static void ModalState(MetroMessageBoxControl control)
{
do
;
while (control.Visible);
}
}
}