test_custommessagebox_test_.../Test_CustomMessageBox/MessageBox.cs
2020-11-26 16:26:55 +01:00

71 lines
2.0 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 Test_CustomMessageBox
{
public partial class MessageBox : Form
{
private static string text, title;
private static MessageBoxButtons buttons;
private static System.Drawing.Image img;
private static DialogResult result;
private static Form form;
public MessageBox()
{
InitializeComponent();
}
private void MessageForm_Load(object sender, EventArgs e)
{
MessageBox.GetMessage(lbText, this, lbImage, btYes, btNo);
}
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();
}
}
}