KeyCodes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dom

    KeyCodes

    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?
  • Peter Duniho

    #2
    Re: KeyCodes

    On Sat, 15 Mar 2008 14:37:49 -0700, Dom <dolivastro@gma il.comwrote:
    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

    Comment

    Working...