using System;
using System.Windows.Forms;
namespace DataStreamInterfaceTest
{
public partial class GetFrameBoundariesDlg : Form
{
///
/// Integer number entered in this form
///
public Int64 From;
public Int64 To;
Int64 lowerLimit;
Int64 upperLimit;
///
/// Default constructor
///
public GetFrameBoundariesDlg()
: this("Enter state please")
{
}
///
/// Constructor with a custom window title.
///
/// Window title
public GetFrameBoundariesDlg(string title)
: this(title, Int64.MinValue, Int64.MaxValue)
{
}
///
/// Constructor with a custom window title, limits and non-empty initial value.
///
/// Window title
/// Lower limit
/// Upper limit
/// Initial value
public GetFrameBoundariesDlg(string title, Int64 lowerLimit, Int64 upperLimit, int initialValue)
: this(title, lowerLimit, upperLimit)
{
fromTextBox.Text = initialValue.ToString();
}
///
/// Constructor with a custom window title and lower/upper limits.
///
/// Window title
/// Lower limit
/// Upper limit
public GetFrameBoundariesDlg(string title, Int64 lowerLimit, Int64 upperLimit)
{
InitializeComponent();
this.Text = title;
this.lowerLimit = lowerLimit;
this.upperLimit = upperLimit;
}
///
/// OK button handler that verifies validity of the entered value.
///
private void okButton_Click(object sender, EventArgs e)
{
Int64 from;
Int64 to;
if (Int64.TryParse(fromTextBox.Text, out from) && from >= lowerLimit && from <= upperLimit &&
Int64.TryParse(toTextBox.Text, out to) && to >= lowerLimit && to <= upperLimit &&
to >= from && to < from + Int32.MaxValue)
{
From = from;
To = to;
DialogResult = DialogResult.OK;
}
else
{
string message = (lowerLimit != 0 || upperLimit != Int32.MaxValue)
? string.Format("Invalid boundaries ({0}..{1})", lowerLimit, upperLimit)
: "Invalid boundaries";
MessageBox.Show(message);
DialogResult = DialogResult.None; /// Prevent closing this window
}
}
}
}