Formatting input text

cdebruin

New member
Joined
Mar 12, 2012
Messages
2
Programming Experience
Beginner
Hi all,

I'm looking to restrict what a user can enter in many textboxes on a form. I have a function written for it, but it's a pain in the ass to call it in the load event and in the textchanged event for each textbox(it starts the form color coded to let you know what is required and what is only a warning). I considered a masked textbox, but I don't necessarily want to control how many characters are entered or where the decimals or other punctuations go.

Is there a simplistic way to accomplish this?
 
You should create a custom control. Create a class that inherits TextBox and then put your code inside the class. You can then simply add instances of your control to your form like you would any other control and all the functionality is already encapsulated within each one. Here's an example:

Numeric Text Box

That handles input validation and text formatting of numbers.
 
I have a function written for it, but it's a pain in the ass to call it in the load event and in the textchanged event for each textbox
You would also only need one event handler for all controls.
 
Back
Top