Disabling Keys

Arg81

Well-known member
Joined
Mar 11, 2005
Messages
949
Location
Midlands, UK
Programming Experience
1-3
Hi All,

I've got a function that stops users pressing certain keys within a textbox.

Has someone got a list or a website that shows the numeric value of each key? I.E / = 47 \ = 92 etc.

Either that, or does anyone know the best way of setting a textbox so only numbers can be entered - no symbols or letters allowed.

cheers!
Luke
 
in the keypress event check to see if the key is numeric:

If IsNumeric(e.KeyChar) = False Then e.Handled = True

the above line checks to see if it's a number or not, and if it's not then it's not passed to the textbox
 
It is not quite such a trivial matter to exclude non-numeric characters. Using that code does not prevent the user pasting whatever they want into the control. You can handle the Ctrl+V combination in the KeyDown event and you can also disable the standard ContextMenu by assigning a blank one. If you don't mind using third party controls, you can get a relatively sophisticated numeric TextBox from here. This library contains many other useful components as well. If you have doubts that the library is free (as many I've referred do) read the page carefully and you'll see that it is not a 30 day trial as some believe.
 
hey jm,

Thanks for the tip, but I only want the "numeric textbox" for the user to enter an ID number to search on.
I've got it all validating if the ID is not found, however if a string was entered I'd get the "input string not correct" error.
I doubt very much they would try to copy and paste something - they're not that clever. It was a case of either do this project in VB.net, or give them crayons and some scrap paper.....

cheers
Luke
 
honest.
They struggle telling their ar*e from their elbow.

I've had to write the documentation for the use of this project in the form of a pop-up book so they understand - too much text will confuse and bore them, I need to keep their minds focused, so will use pictures and pop ups instead.

...and I bet some people won't believe me on this!!!!!
 
Back
Top