#if FRAMEWORK20 using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using System.ComponentModel; namespace DevComponents.DotNetBar.Validator { public class CustomValidator : ValidatorBase { #region Events public event ValidateValueEventHandler ValidateValue; #endregion #region Constructors /// /// Initializes a new instance of the CustomValidator class. /// public CustomValidator() { } #endregion #region Implementation public override bool Validate(System.Windows.Forms.Control input) { ValidateValueEventArgs e = new ValidateValueEventArgs(input); OnValidateValue(e); if (this.SuperValidator != null) this.SuperValidator.InvokeCustomValidatorValidateValue(this, e); this.LastValidationResult = e.IsValid; return LastValidationResult; } protected virtual void OnValidateValue(ValidateValueEventArgs e) { ValidateValueEventHandler h = ValidateValue; if (h != null) h(this, e); } private object _Tag; /// /// Gets or sets custom data associated with the validator /// [DefaultValue((string)null), Localizable(false), TypeConverter(typeof(StringConverter)), Category("Data"), Description("Custom data associated with the validator")] public object Tag { get { return _Tag; } set { _Tag = value; } } #endregion } /// /// Defines delegate for CustomValidator ValidateValue event. /// /// Sender /// Event arguments public delegate void ValidateValueEventHandler(object sender, ValidateValueEventArgs e); public class ValidateValueEventArgs : EventArgs { /// /// Gets the reference to the control to validate. /// public readonly Control ControlToValidate; /// /// Gets or sets whether control's value is valid. /// public bool IsValid = false; /// /// Initializes a new instance of the ValidateValueEventArgs class. /// /// Control to validate. public ValidateValueEventArgs(Control controlToValidate) { ControlToValidate = controlToValidate; } } } #endif