Integrating with Windows Forms

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The latest Enterprise Library information can be found at the Enterprise Library site.

You can integrate the Validation Application Block with Windows Forms applications. For example, you can use the application block to validate information a user enters into a Windows Form. Windows Forms is integrated with the Validation Application Block through the types defined in the Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WinForms assembly.

The ValidationProvider class defined in this assembly provides the main integration point. This class is an extender provider that adds properties to Windows Forms controls. This provider allows you to specify how to use the Validation Application Block to validate the controls' values.

You can perform validation automatically by using the Control.Validating event or you can initiate it in your code by invoking the ValidationProvider.PerformValidation(Control) method. In both cases, you must use the validation provider to configure the control.

You can also specify an instance of the ErrorProvider class for the control. If you do this, the validation errors that result if the validation fails are sent to the error provider as a properly formatted error message.

The ValidationProvider.Enabled property enables and disables the validation provider. When it is disabled no validation occurs, the validation provider is considered valid, and any error messages posted to the ErrorProvider are cleared. When it is re-enabled, the provider continues to be valid and does not post any error messages until validation is triggered again.

For an example of how to use the ValidationProvider class to validate user input in a Windows Forms application, see the Validation QuickStart.