KeyCodes

D

Dom

In some events for the TextBox, I get only the KeyCode, that is, a
number. In VB, I used to be able to convert this to a char. How do I
do that in CS?
 
P

Peter Duniho

In some events for the TextBox, I get only the KeyCode, that is, a
number. In VB, I used to be able to convert this to a char. How do I
do that in CS?

You don't, and you don't do it in VB either. If you've got a KeyCode,
then you're dealing with an event that uses keyboard scan codes, not
characters. For example, KeyDown instead of KeyPress.

Some key codes use the same value as a corresponding character, and you
could get away with casting from one to the other. But it's a bad idea to
do so, as the fact that they are the same is for all intents and purposes
a coincidence. I mean, obviously it was intentional, but the reason for
it being intentional existed and was relevant a long time ago. In .NET,
use a key code-based event when you want a key code, and use a
character-based event when you want a character.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top