69 lines
2.3 KiB
C#
69 lines
2.3 KiB
C#
using System;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Statistics.Forms
|
|
{
|
|
public partial class ModelessForm : Form
|
|
{
|
|
/// <summary>
|
|
/// Called from the state machine when an operation forces a modeless dialog close.
|
|
/// </summary>
|
|
public static void CloseForm()
|
|
{
|
|
if (CloseFormHandler == null) return;
|
|
try { CloseFormHandler(null, null); }
|
|
catch (Exception) { }
|
|
}
|
|
public static event EventHandler<EventArgs> CloseFormHandler;
|
|
|
|
void OnCloseForm(object sender, EventArgs args)
|
|
{
|
|
DialogResult = DialogResult.Cancel;
|
|
Close();
|
|
}
|
|
|
|
|
|
public string Title;
|
|
public string Message;
|
|
public Color BackgroundColor;
|
|
public Color TextColor;
|
|
public Font TextFont;
|
|
public string FontFamily;
|
|
public int FontSize;
|
|
public FontStyle FontStyle;
|
|
|
|
|
|
/// <summary>
|
|
/// Constructor to be used by the application
|
|
/// </summary>
|
|
/// <param name="title">Window title</param>
|
|
/// <param name="message">Displayed message</param>
|
|
public ModelessForm()
|
|
{
|
|
InitializeComponent();
|
|
ControlBox = false;
|
|
|
|
CloseFormHandler += delegate(object sender, EventArgs args)
|
|
{
|
|
if (InvokeRequired) { Invoke(new EventHandler<EventArgs>(OnCloseForm), sender, args); }
|
|
else OnCloseForm(sender, args);
|
|
};
|
|
}
|
|
|
|
private void ModelessForm_Load(object sender, EventArgs e)
|
|
{
|
|
if (Title != null) Text = Title;
|
|
if (Message != null) label1.Text = Message;
|
|
if (BackgroundColor != null) BackColor = BackgroundColor;
|
|
if (TextColor != null) ForeColor = TextColor;
|
|
if (FontFamily != null) label1.Font = new Font(FontFamily, FontSize, FontStyle);
|
|
|
|
float textWidth = Graphics.FromImage(new Bitmap(1, 1)).MeasureString(label1.Text, label1.Font).Width;
|
|
float textHeight = Graphics.FromImage(new Bitmap(1, 1)).MeasureString(label1.Text, label1.Font).Height;
|
|
Width = (int)textWidth + 120; /// Form width calculated from the text width
|
|
Height += (int)textHeight; /// Form height calculated from the text height
|
|
}
|
|
}
|
|
}
|