84 lines
2.7 KiB
C#
84 lines
2.7 KiB
C#
using System;
|
|
using System.Windows.Forms;
|
|
|
|
namespace DataStreamInterfaceTest
|
|
{
|
|
public partial class GetIntegerNumberDlg : Form
|
|
{
|
|
/// <summary>
|
|
/// Integer number entered in this form
|
|
/// </summary>
|
|
public int Number;
|
|
|
|
int lowerLimit;
|
|
int upperLimit;
|
|
|
|
|
|
/// <summary>
|
|
/// Default constructor
|
|
/// </summary>
|
|
public GetIntegerNumberDlg()
|
|
: this("Enter integer number please")
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Constructor with a custom window title.
|
|
/// </summary>
|
|
/// <param name="title">Window title</param>
|
|
public GetIntegerNumberDlg(string title)
|
|
: this(title, Int32.MinValue, Int32.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 GetIntegerNumberDlg(string title, int lowerLimit, int upperLimit, int initialValue)
|
|
: this(title, lowerLimit, upperLimit)
|
|
{
|
|
numberTextBox.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 GetIntegerNumberDlg(string title, int lowerLimit, int 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)
|
|
{
|
|
int number;
|
|
if (int.TryParse(numberTextBox.Text, out number) && number >= lowerLimit && number <= upperLimit)
|
|
{
|
|
Number = number;
|
|
DialogResult = DialogResult.OK;
|
|
}
|
|
else
|
|
{
|
|
string message = (lowerLimit != Int32.MinValue || upperLimit != Int32.MaxValue)
|
|
? string.Format("Invalid integer number ({0}..{1})", lowerLimit, upperLimit)
|
|
: "Invalid integer number";
|
|
MessageBox.Show(message);
|
|
DialogResult = DialogResult.None; /// Prevent closing this window
|
|
}
|
|
}
|
|
}
|
|
}
|