87 lines
3.3 KiB
C#
87 lines
3.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace MaterialSkin.Controls
|
|
{
|
|
public partial class MaterialMessageBox : MaterialForm
|
|
{
|
|
[Browsable(false)]
|
|
private MaterialSkinManager SkinManager => MaterialSkinManager.Instance;
|
|
private MaterialMessageBox()
|
|
{
|
|
InitializeComponent();
|
|
BackColor = SkinManager.GetApplicationBackgroundColor();
|
|
Left = 0;
|
|
Width = Screen.PrimaryScreen.WorkingArea.Width;
|
|
Top = (Screen.PrimaryScreen.WorkingArea.Height - Height) / 2;
|
|
lblTitle.BackColor = SkinManager.ColorScheme.PrimaryColor;
|
|
lblTitle.ForeColor= SkinManager.ColorScheme.TextColor;
|
|
lblText.Left = (Width - lblText.Width) / 2;
|
|
|
|
}
|
|
|
|
private void AlignControls()
|
|
{
|
|
pnlButtons.Left = (Width - pnlButtons.Width) / 2;
|
|
}
|
|
|
|
public static DialogResult Show(string text)
|
|
{
|
|
return Show(null, text, string.Empty, MessageBoxButtons.OK);
|
|
}
|
|
public static DialogResult Show(IWin32Window owner,string text, string caption, MessageBoxButtons buttons)
|
|
{
|
|
var mb = new MaterialMessageBox();
|
|
mb.lblTitle.Text = caption;
|
|
mb.lblText.Text = text;
|
|
List<DialogResult> results;
|
|
switch (buttons)
|
|
{
|
|
case MessageBoxButtons.OK:
|
|
results=new List<DialogResult>(){DialogResult.OK};
|
|
break;
|
|
case MessageBoxButtons.OKCancel:
|
|
results = new List<DialogResult>() { DialogResult.OK,DialogResult.Cancel };
|
|
break;
|
|
case MessageBoxButtons.AbortRetryIgnore:
|
|
results = new List<DialogResult>() { DialogResult.Abort,DialogResult.Retry,DialogResult.Ignore };
|
|
break;
|
|
case MessageBoxButtons.YesNoCancel:
|
|
results = new List<DialogResult>() { DialogResult.Yes,DialogResult.No,DialogResult.Cancel };
|
|
break;
|
|
case MessageBoxButtons.YesNo:
|
|
results = new List<DialogResult>() { DialogResult.Yes,DialogResult.No };
|
|
break;
|
|
case MessageBoxButtons.RetryCancel:
|
|
results = new List<DialogResult>() { DialogResult.Retry,DialogResult.Cancel };
|
|
break;
|
|
default:
|
|
throw new ArgumentOutOfRangeException(nameof(buttons), buttons, null);
|
|
}
|
|
|
|
var btns=Enum.GetNames(typeof(DialogResult));
|
|
foreach (var btn in results)
|
|
{
|
|
MaterialRaisedButton opt = new MaterialRaisedButton();
|
|
opt.Size = new Size(180, 60);
|
|
opt.Margin = new Padding(10, 20, 10, 0);
|
|
opt.Text = Enum.GetName(typeof(DialogResult),btn);
|
|
opt.Click += (sender, args) =>
|
|
mb.DialogResult = btn;
|
|
mb.pnlButtons.Controls.Add(opt);
|
|
mb.AlignControls();
|
|
}
|
|
|
|
return mb.ShowDialog(owner);
|
|
}
|
|
|
|
}
|
|
}
|