tbf/TestBenchFramework/BenchControl/Operations/AskYesNoForm.cs

58 lines
1.2 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 AskYesNoForm : Form
{
/// One of the following two variables set to 'true' when the form closes
public bool CompletedYes;
public bool CompletedNo;
public AskYesNoForm(string question)
{
InitializeComponent();
ControlBox = false;
Localize();
questionLabel.Text = question;
float textWidth = Graphics.FromImage(new Bitmap(1, 1)).MeasureString(questionLabel.Text, questionLabel.Font).Width;
int rqrdFormWidth = (int)textWidth + 80; /// Form width calculated from the text width
if (rqrdFormWidth > Width)
{
int shift = (rqrdFormWidth - Width) / 2;
Width = rqrdFormWidth;
yesButton.Left += shift;
noButton.Left += shift;
}
}
void Localize()
{
yesButton.Text = Strings.YesBtn;
noButton.Text = Strings.NoBtn;
Text = Strings.Question;
}
private void yesButton_Click(object sender, EventArgs e)
{
CompletedYes = true;
Close();
}
private void noButton_Click(object sender, EventArgs e)
{
CompletedNo = true;
Close();
}
}
}