Re: KeyCodes by Peter
Peter
Sat Mar 15 17:28:05 CDT 2008
On Sat, 15 Mar 2008 14:37:49 -0700, Dom <dolivastro@gmail.com> wrote:
> 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