protected override bool Validate()
{
bool valid = true;
if (IsEnabled && ControlToValidate.Enabled)
{
// Is valid if different than initial value,
// which is not necessarily an empty string
string controlValue = ControlToValidate.Text.Trim();
string initialValue;
if (_initialValue == null) initialValue = "";
else initialValue = _initialValue.Trim();
double value;
_isValid = double.TryParse(controlValue, out value);
// Display an error if ControlToValidate is invalid
string errorMessage = "";
if (!_isValid)
{
errorMessage = _errorMessage;
if (_icon != null)
ErrorProvider.Icon = _icon;
valid = false;
if (ControlToValidate is ATMLControl)
((ATMLControl)ControlToValidate).HasErrors = true;
}
ErrorProvider.SetError(_controlToValidate, errorMessage);
}
return valid;
}