Search code examples
c#visual-studio-2015textboxlistboxkeydown

e.KeyCode returns 'A' instead of 'a'


In listBox_KeyDown, I evaluate the e.KeyCode condition. But it detects Upper-case characters instead of the lower-case (which is actually typed). How do I get it to capture the actual character typed? Code follows:

bool isLetterOrDigit = char.IsLetterOrDigit((char)e.KeyCode);
if (isLetterOrDigit == true)
{
    //Add the char to textBox
    txtINAME.Text += (char)e.KeyCode;
}

Solution

  • Use the KeyPress event, it has a KeyChar property in the KeyPressEventArgs. It will get you the actual character being pressed