using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace CustomMessageBox { public static class CustomMessageBox { private string text, title; private MessageBoxButtons buttons; private System.Drawing.Image img; private DialogResult result; private Form form; public static DialogResult Show(string mText, string mTitle, MessageBoxButtons mButtons, System.Drawing.Image mImg, Form mForm) { text = mText; title = mTitle; buttons = mButtons; img = mImg; form = mForm; form.ShowDialog(); return result; } public static void GetMessage(Control mTextControl, Control mTitleControl, Control mImgControl, Control btYes, Control btNo) { mTextControl.Text = text; mTitleControl.Text = title; if (buttons != MessageBoxButtons.YesNo) { btYes.Visible = false; btNo.Text = "OK"; } btYes.Click += new EventHandler(Yes); btNo.Click += new EventHandler(No); mImgControl.BackgroundImageLayout = ImageLayout.Center; mImgControl.BackgroundImage = img; result = DialogResult.Abort; } private static void Yes(object sender, EventArgs e) { result = DialogResult.Yes; form.Close(); } private static void No(object sender, EventArgs e) { result = DialogResult.No; form.Close(); } } }