public void RegisterControl(Control control, Func <string> validationFunc) { if (control != null && validationFunc != null) { ErrorProvider errorProvider = new ErrorProvider(); EventHandler validatedHandler = (sender, e) => { string msg = validationFunc(); if (msg != null) { errorProvider.SetIconPadding(control, DetermineErrorIconPadding(control)); errorProvider.SetError(control, msg); } else { errorProvider.SetError(control, String.Empty); } Validate(); }; EventHandler textChangedHandler = (sender, e) => { if (validationFunc() == null) { errorProvider.SetError(control, String.Empty); } Validate(); }; ControlRecord record = new ControlRecord() { Control = control, ValidationFunc = validationFunc, ErrorProvider = errorProvider, ValidatedHandler = validatedHandler, TextChangedHandler = textChangedHandler, }; record.Link(); _controls.Add(record); _validateFuncs.Add(validationFunc); } }
public void RegisterControl(Control control, Func<string> validationFunc) { if (control != null && validationFunc != null) { ErrorProvider errorProvider = new ErrorProvider(); EventHandler validatedHandler = (sender, e) => { string msg = validationFunc(); if (msg != null) { errorProvider.SetIconPadding(control, DetermineErrorIconPadding(control)); errorProvider.SetError(control, msg); } else errorProvider.SetError(control, String.Empty); Validate(); }; EventHandler textChangedHandler = (sender, e) => { if (validationFunc() == null) errorProvider.SetError(control, String.Empty); Validate(); }; ControlRecord record = new ControlRecord() { Control = control, ErrorProvider = errorProvider, ValidatedHandler = validatedHandler, TextChangedHandler = textChangedHandler, }; record.Link(); _controls.Add(record); _validateFuncs.Add(validationFunc); } }