Hi everyone, I have 2 questions about keyboard events:
1) I want a text box to accept certain input keys only (say, numbers and +- signs only). This can be done easily: in the KeyPress event, use if-then-else cases to check the key input, if it is in the unwelcomed keys list, use the code "KeyAscii = 0" to "neutralize" the input, so nothing goes to the textbox. Unfortunately the "Del" key is also in the unwelcomed list - and too bad KeyPress does not support "Del". I was so happy when I discovered that using KeyDown instead will support all keys, but later I found out the trick "KeyCode = 0" does not apply in KeyDown... a dilemma. Does anyone here know a way to make KeyPress knowing "Del", or KeyDown knowing "KeyCode = 0"? (I try not to use input mask textbox because I don't like it putting those _ all over the place, plus I don't know how to make it to allow +- signs only in the 1st character.)
2. Which one (KeyPress or KeyDown) do you use more? I noticed that they are different not only in the number of keys supported, but also the values of KeyAscii and KeyCode, so I want to pick a more popular one.
1) I want a text box to accept certain input keys only (say, numbers and +- signs only). This can be done easily: in the KeyPress event, use if-then-else cases to check the key input, if it is in the unwelcomed keys list, use the code "KeyAscii = 0" to "neutralize" the input, so nothing goes to the textbox. Unfortunately the "Del" key is also in the unwelcomed list - and too bad KeyPress does not support "Del". I was so happy when I discovered that using KeyDown instead will support all keys, but later I found out the trick "KeyCode = 0" does not apply in KeyDown... a dilemma. Does anyone here know a way to make KeyPress knowing "Del", or KeyDown knowing "KeyCode = 0"? (I try not to use input mask textbox because I don't like it putting those _ all over the place, plus I don't know how to make it to allow +- signs only in the 1st character.)
2. Which one (KeyPress or KeyDown) do you use more? I noticed that they are different not only in the number of keys supported, but also the values of KeyAscii and KeyCode, so I want to pick a more popular one.