89 lines
2.9 KiB
C#
89 lines
2.9 KiB
C#
|
|
using System;
|
|||
|
|
using System.Windows.Forms;
|
|||
|
|
|
|||
|
|
namespace DataStreamInterfaceTest
|
|||
|
|
{
|
|||
|
|
public partial class GetFrameBoundariesDlg : Form
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// Integer number entered in this form
|
|||
|
|
/// </summary>
|
|||
|
|
public Int64 From;
|
|||
|
|
public Int64 To;
|
|||
|
|
|
|||
|
|
Int64 lowerLimit;
|
|||
|
|
Int64 upperLimit;
|
|||
|
|
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Default constructor
|
|||
|
|
/// </summary>
|
|||
|
|
public GetFrameBoundariesDlg()
|
|||
|
|
: this("Enter state please")
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Constructor with a custom window title.
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="title">Window title</param>
|
|||
|
|
public GetFrameBoundariesDlg(string title)
|
|||
|
|
: this(title, Int64.MinValue, Int64.MaxValue)
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Constructor with a custom window title, limits and non-empty initial value.
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="title">Window title</param>
|
|||
|
|
/// <param name="lowerLimit">Lower limit</param>
|
|||
|
|
/// <param name="upperLimit">Upper limit</param>
|
|||
|
|
/// <param name="initialValue">Initial value</param>
|
|||
|
|
public GetFrameBoundariesDlg(string title, Int64 lowerLimit, Int64 upperLimit, int initialValue)
|
|||
|
|
: this(title, lowerLimit, upperLimit)
|
|||
|
|
{
|
|||
|
|
fromTextBox.Text = initialValue.ToString();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Constructor with a custom window title and lower/upper limits.
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="title">Window title</param>
|
|||
|
|
/// <param name="lowerLimit">Lower limit</param>
|
|||
|
|
/// <param name="upperLimit">Upper limit</param>
|
|||
|
|
public GetFrameBoundariesDlg(string title, Int64 lowerLimit, Int64 upperLimit)
|
|||
|
|
{
|
|||
|
|
InitializeComponent();
|
|||
|
|
this.Text = title;
|
|||
|
|
this.lowerLimit = lowerLimit;
|
|||
|
|
this.upperLimit = upperLimit;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// OK button handler that verifies validity of the entered value.
|
|||
|
|
/// </summary>
|
|||
|
|
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
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|