This is the example custom message box class can be used inside plugin I’m using. :
public class PrettyMessageBox : Form
{
int TEXT_BOX_WIDTH = 280;
int TEXT_BOX_HEIGHT = 30;
private string message_contents;
private string title_string;
private Panel titleBar;
private Button closeButtonOnTitle;
private Point mouseOffsetOnTitle;
private bool isMouseDownOnTitle = false;
private Label titleLabel;
RichTextBox MessageTextBox;
private string language = "kr";
private Button confirmationButtonOnBottom;
private const string RegistryPath = @"Software\XXXX\XXXX\Settings";
public PrettyMessageBox(string _message_contents)
{
message_contents = _message_contents;
title_string = "XXXXX";
PopUpMessageBox();
}
public PrettyMessageBox(string _message_contents, string _title_string)
{
message_contents = _message_contents;
title_string = _title_string;
PopUpMessageBox();
}
public PrettyMessageBox(string _message_contents, string _title_string, int _width, int _height)
{
message_contents = _message_contents;
title_string = _title_string;
TEXT_BOX_WIDTH = _width;
TEXT_BOX_HEIGHT = _height;
PopUpMessageBox();
}
private void PopUpMessageBox()
{
// 001.
this.FormBorderStyle = FormBorderStyle.None;
this.StartPosition = FormStartPosition.CenterScreen;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Padding = new Padding(1);
// 002.
MessageTextBox = new RichTextBox();
MessageTextBox.Multiline = true;
MessageTextBox.ReadOnly = true;
MessageTextBox.ScrollBars = RichTextBoxScrollBars.None;
MessageTextBox.TabStop = false;
MessageTextBox.Enter += (s, e) => this.ActiveControl = null;
MessageTextBox.Cursor = Cursors.Arrow;
// 003.
string language = ReadLanguageOption();
MessageTextBox.Text = message_contents;
if (language == "kr")
{
MessageTextBox.Font = new("맑은 고딕", 10);
}
else
{
MessageTextBox.Font = new("Calibri", 10);
}
MessageTextBox.Size = new Size(TEXT_BOX_WIDTH, TEXT_BOX_HEIGHT);
this.Size = new Size(TEXT_BOX_WIDTH + 20, TEXT_BOX_HEIGHT + 80);
MessageTextBox.Location = new Point(
(this.ClientSize.Width - MessageTextBox.Width) / 2,
(this.ClientSize.Height - MessageTextBox.Height) / 2
);
this.Controls.Add(MessageTextBox);
// 004.
titleBar = new Panel();
titleBar.Dock = DockStyle.Top;
titleBar.Height = 30;
titleBar.MouseDown += titleBarMouseDown;
titleBar.MouseMove += titleBarMouseMove;
titleBar.MouseUp += titleBarMouseUp;
this.Controls.Add(titleBar);
// 005.
closeButtonOnTitle = new Button();
closeButtonOnTitle.Text = "r"; // = X in Webdings font
closeButtonOnTitle.Font = new Font("Webdings", 10, FontStyle.Bold);
closeButtonOnTitle.FlatStyle = FlatStyle.Flat;
closeButtonOnTitle.FlatAppearance.BorderSize = 0;
closeButtonOnTitle.Size = new Size(30, 30);
closeButtonOnTitle.Location = new Point(titleBar.Width - closeButtonOnTitle.Width, 0);
closeButtonOnTitle.Anchor = AnchorStyles.Top | AnchorStyles.Right;
closeButtonOnTitle.Click += (s, e) =>
{
this.Close();
};
titleBar.Controls.Add(closeButtonOnTitle);
// 006.
titleLabel = new Label();
titleLabel.Text = title_string;
titleLabel.Font = new Font("맑은 고딕", 10, FontStyle.Regular);
titleLabel.TextAlign = ContentAlignment.MiddleLeft;
titleLabel.AutoSize = false;
titleLabel.Dock = DockStyle.Left;
titleLabel.Width = titleBar.Width - closeButtonOnTitle.Width;
titleLabel.MouseDown += titleBarMouseDown;
titleLabel.MouseUp += titleBarMouseUp;
titleLabel.MouseMove += titleBarMouseMove;
titleBar.Controls.Add(titleLabel);
titleLabel.BringToFront();
// 007.
confirmationButtonOnBottom = new Button();
if (language == "kr")
{
confirmationButtonOnBottom.Text = "확인";
confirmationButtonOnBottom.Font = new Font("맑은 고딕", 10);
}
else
{
confirmationButtonOnBottom.Text = "OK";
confirmationButtonOnBottom.Font = new Font("Calibri", 10);
}
confirmationButtonOnBottom.FlatStyle = FlatStyle.Flat;
confirmationButtonOnBottom.FlatAppearance.BorderColor = Color.LightGray;
confirmationButtonOnBottom.Size = new Size(130, 25);
int center_x = (this.ClientSize.Width - confirmationButtonOnBottom.Width) / 2;
int y = MessageTextBox.Bottom + 10;
confirmationButtonOnBottom.Location = new Point(center_x, y);
confirmationButtonOnBottom.Click += (s, e) => { this.Close(); }; // sender, event args
confirmationButtonOnBottom.MouseEnter += (s, e) =>
{
confirmationButtonOnBottom.BackColor = Color.FromArgb(211, 240, 224); // Hovered fill color
confirmationButtonOnBottom.FlatAppearance.BorderColor = Color.FromArgb(134, 191, 160); // Hovered border
};
confirmationButtonOnBottom.MouseLeave += (s, e) =>
{
confirmationButtonOnBottom.BackColor = Color.White;
confirmationButtonOnBottom.FlatAppearance.BorderColor = Color.FromArgb(169, 169, 169);
};
this.Controls.Add(confirmationButtonOnBottom);
}
private void titleBarMouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseOffsetOnTitle = new Point(-e.X, -e.Y);
isMouseDownOnTitle = true;
}
}
private void titleBarMouseMove(object sender, MouseEventArgs e)
{
if (isMouseDownOnTitle)
{
Point mousePos = Control.MousePosition;
mousePos.Offset(mouseOffsetOnTitle.X, mouseOffsetOnTitle.Y);
this.Location = mousePos;
}
}
private void titleBarMouseUp(object sender, MouseEventArgs e)
{
isMouseDownOnTitle = false;
}
private string ReadLanguageOption()
{
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(RegistryPath))
{
if (key != null)
{
string languageOption = key.GetValue("Language") as string;
return languageOption;
}
}
return "kr";
}
protected override void OnActivated(EventArgs e)
{
base.OnActivated(e);
ApplyCustomStyles();
}
// borderlines
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Color borderColor = Color.FromArgb(74, 83, 86);
ControlPaint.DrawBorder(e.Graphics, this.ClientRectangle,
borderColor, 2, ButtonBorderStyle.Solid, // Left
borderColor, 2, ButtonBorderStyle.Solid, // Top
borderColor, 2, ButtonBorderStyle.Solid, // Right
borderColor, 2, ButtonBorderStyle.Solid // Bottom
);
}
// shadows on borderlines
protected override CreateParams CreateParams
{
get
{
const int CS_DROPSHADOW = 0x00020000;
CreateParams cp = base.CreateParams;
cp.ClassStyle |= CS_DROPSHADOW;
return cp;
}
}
private void ApplyCustomStyles()
{
Color darkGray = Color.FromArgb(70, 70, 70);
this.BackColor = Color.White;
this.ForeColor = darkGray;
MessageTextBox.BackColor = Color.White;
MessageTextBox.ForeColor = Color.DarkGray;
MessageTextBox.BorderStyle = BorderStyle.None;
titleBar.BackColor = Color.FromArgb(74, 83, 86);
titleBar.ForeColor = darkGray;
closeButtonOnTitle.ForeColor = Color.DarkGray;
closeButtonOnTitle.BackColor = Color.Transparent;
titleLabel.ForeColor = Color.DarkGray;
titleLabel.BackColor = Color.Transparent;
confirmationButtonOnBottom.BackColor = Color.White;
confirmationButtonOnBottom.ForeColor = darkGray;
confirmationButtonOnBottom.BackColor = Color.White;
confirmationButtonOnBottom.ForeColor = darkGray;
}
} // end of PrettyMessageBox class