Always uppercase ... (C # winforms)

I have TextBoxin my form, and I added this event to it:

private void txtValue_KeyDown(object sender, KeyEventArgs e)
        {
            MessageBox.Show(e.KeyData.ToString());
        }

But he always types uppercase letters, although I entered a lowercase letter in the text box. See image below:

my form

How do I get the correct display? Thank...

+3
source share
2 answers

KeyDownand KeyUpuse KeyEventArgsthat provides an enumeration Keysthrough the property KeyData. The enumeration has no representation for lowercase alphabetic values.

http://msdn.microsoft.com/en-us/library/system.windows.forms.keys.aspx

The event KeyPressallows you to get the actual character of the key pressed through KeyPressEventArgs.KeyChar.

private void txtValue_KeyPress(object sender, KeyPressEventArgs e)
{
    MessageBox.Show(e.KeyChar.ToString());
} 
+2

KeyPress , KeyChar KeyPressEventArgs, .

+3

Source: https://habr.com/ru/post/1763928/


All Articles