Few days ago I worked on some winforms and needed some validator controls. I thought that the winforms should have the same validator controls as webforms. However I could not find them. So I used the ErrorProvider control which also does a good job. However it does not come with any regular expressions or something like that to validate any email or web url. You will have to find the regular expression on your own. A good website to to do that is RegExLib. This Website already contains many pre-defined regular expressions. It also contains basics to learn regular expressions. Let's get back to the ErrorProvider. To implement the ErrorProvider in your project, just drop it in your form or double click it and you will see it below the form in a bar. Now each control on your form will get an extra property called: Error on ErrorProvider1. You can set the default error message here if you want. If not you can leave it blank and in your code you can access the property via the method SetError. Just define the message in the SetError method and it works. If an error occurs you won't get any MessageBox or the errormessage isn't displayed under the control. Instead you will see a small icon right from the control which will blink for a few times. If you then hover over the control, you will see the errormessage as a tooltip. Something like this:

You can even use your own icons for that.

Update: I just had a short IM conversation with Christian Weyer and he told me that there aren't any validator controls for win forms. One way would be to use the Validating event, but that's old school style and he hopes and actually thinks they will be there in 2.0. Microsoft don't disappoint me and Chris :-)



Comments have been disabled for this content.