alexmaster_2004 said:
Louis, Thanks for reply.
but i want to use a textbox.
First, please don't delete old text from the post, it means you have to look
through previous posts in the thread, rather than opening the last one
Here's my suggestion:
You can do this via a two-pronged approach, using the keypress and changed
events in conjunction. First you need to look at how the value in a textbox
can be changed:
Keypress.
Paste via keyboard
Paste via context menu
Drag-drop (if implemented)
Changed in code.
In the keypress event, if the user presses a printable character and it's
not one you like, set the handled flag on the eventargs to true, as this
will stop the keypress getting into the textbox.
In the changed event handler, you need to know that the change hasn't first
been through your keypress handler with a valid character. If it has, do
nothing. If it hasn't, check if the new changed value is valid or not. If it
isn't, reset the value in the textbox to it previous (you need to store
this) valid value.
cheers
Simon