Int32 input (it could be easily adapted for other types such as System. It supports copy/paste operations and negative numbers: This is exactly what the Validated/Validating events were designed for.

numericupdown validating-48

Text property in the Validating event and set when the data is invalid. Cancel=True, the user can't leave the field, but you will need to give them some kind of feedback that something's wrong.

I change the box's background color to light red to indicate a problem. If it is something wrong, the last good value will be restored.

In the past I've done this kind of validation by overloading the Key Press event and just removing characters which didn't fit the specification.

I've looked at the Masked Text Box control but I'd like a more general solution that could work with perhaps a regular expression, or depend on the values of other controls.

Raises the Invalidated event with a specified region of the control to invalidate.(Inherited from Control.) gives you the ability to create controls that can be used in multiple places within an application or organization.

You can include all the code needed for validation of common data you ask the user to input; some examples of this are e-mail addresses (see Example section), telephone numbers, and postal codes.Another efficient use of the user control is to simply preload a Combo Box or List Box with static items you commonly use in almost every application; some examples of this are countries/regions, cities, states, and office locations.For more information about authoring custom controls, see Developing Custom Windows Forms Controls with the . You might consider creating a namespace that contains several classes of user controls and compiling it into one DLL.You would hope that the form validation would catch that though, since at some point you're gonna want to do an Int32.Try Parse or [email protected] Grubijan, Is Control has nothing to do with the Control key; it returns whether or not a char is a control char.Make sure to set it back to I have made something for this on Code Plex. The source is a bit too large to publish here, but here is a link to the class that handles the core of this logic.