72 lines
1.5 KiB
C#
72 lines
1.5 KiB
C#
///
|
|
/// Copyright (c) 2013-2017 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
using TBF.Resources;
|
|
|
|
namespace TBF.BenchControl.Operations
|
|
{
|
|
public partial class MessageBoxForm : Form, GenericDevices.IHasCompleted
|
|
{
|
|
/// Set to 'true' when the form closes
|
|
public bool Completed { get { return completed; } }
|
|
bool completed;
|
|
|
|
|
|
public MessageBoxForm(string message)
|
|
{
|
|
InitializeComponent();
|
|
ControlBox = false;
|
|
|
|
Localize();
|
|
messageLabel.Text = message;
|
|
|
|
float textWidth = Graphics.FromImage(new Bitmap(1, 1)).MeasureString(messageLabel.Text, messageLabel.Font).Width;
|
|
int rqrdFormWidth = (int)textWidth + 80; /// Form width calculated from the text width
|
|
|
|
if (rqrdFormWidth > Width)
|
|
{
|
|
int shift = (rqrdFormWidth - Width) / 2;
|
|
Width = rqrdFormWidth;
|
|
okButton.Left += shift;
|
|
}
|
|
|
|
completed = false;
|
|
StartForceCloseHandler();
|
|
}
|
|
|
|
void Localize()
|
|
{
|
|
Text = Strings.Message;
|
|
okButton.Text = Strings.OkBtnText;
|
|
}
|
|
|
|
private void okButton_Click(object sender, EventArgs e)
|
|
{
|
|
completed = true;
|
|
Close();
|
|
}
|
|
|
|
#region Forced close handling
|
|
|
|
public void StartForceCloseHandler()
|
|
{
|
|
UiBridge.Bridge.CloseQandAFormHandler += delegate(object sender, EventArgs args)
|
|
{
|
|
if (InvokeRequired) { Invoke(new EventHandler<EventArgs>(OnForceClose), sender, args); }
|
|
else OnForceClose(sender, args);
|
|
};
|
|
}
|
|
|
|
private void OnForceClose(object sender, EventArgs args)
|
|
{
|
|
DialogResult = DialogResult.Cancel;
|
|
Close();
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|