tbf/TBF/UI/Item/EditString.cs
2019-10-30 09:24:50 +01:00

48 lines
1.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace TBF.UI.Item
{
public class EditString
{
string name;
string variable;
IList<string> alreadyUsed;
TextBox textBox;
public EditString(string name, ref string variable, IList<string> alreadyUsed)
{
this.name = name;
this.variable = variable;
this.alreadyUsed = alreadyUsed;
this.textBox = new TextBox();
}
public EditString(string name, ref string variable)
: this (name, ref variable, new List<string>())
{
}
public string Name() { return name; }
public Control EmbeddedControl() { return textBox; }
public string Print() { return variable; }
public void Update(string strValue) { variable = strValue; }
public bool Validate(string strValue, out string message)
{
if (alreadyUsed.Contains(strValue))
{
message = string.Format("Value '{0}' was already used", strValue);
return false;
}
else
{
message = string.Empty;
return true;
}
}
}
}