65 lines
1.8 KiB
C#
65 lines
1.8 KiB
C#
using System;
|
|
using System.Windows.Forms;
|
|
|
|
namespace TBF.UI.Item
|
|
{
|
|
public class EditInt : IEditItem
|
|
{
|
|
string name;
|
|
int variable;
|
|
int lowerLimit;
|
|
int upperLimit;
|
|
TextBox textBox;
|
|
|
|
public EditInt(string name, ref int variable, int lowerLimit, int upperLimit)
|
|
{
|
|
this.name = name;
|
|
this.variable = variable;
|
|
this.lowerLimit = lowerLimit;
|
|
this.upperLimit = upperLimit;
|
|
|
|
this.textBox = new TextBox();
|
|
}
|
|
|
|
public EditInt(string name, ref int variable, int lowerLimit)
|
|
: this (name, ref variable, lowerLimit, Int32.MaxValue)
|
|
{
|
|
}
|
|
|
|
public EditInt(string name, ref int variable)
|
|
: this(name, ref variable, Int32.MinValue, Int32.MaxValue)
|
|
{
|
|
}
|
|
|
|
public string Name() { return name; }
|
|
public Control EmbeddedControl() { return textBox; }
|
|
public string Print() { return variable.ToString(); }
|
|
public void Update(string strValue) { variable = int.Parse(strValue); }
|
|
|
|
public bool Validate(string strValue, out string message)
|
|
{
|
|
int dummy;
|
|
if (!int.TryParse(strValue, out dummy))
|
|
{
|
|
message = string.Format("{0} is invalid", name);
|
|
return false;
|
|
}
|
|
else if (dummy < lowerLimit)
|
|
{
|
|
message = string.Format("{0} is smaller then {1}", name, lowerLimit);
|
|
return false;
|
|
}
|
|
else if (dummy > upperLimit)
|
|
{
|
|
message = string.Format("{0} is larger then {1}", name, upperLimit);
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
message = string.Empty;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|