Always in upper case… (C# winforms)

前端 未结 2 1334
情书的邮戳
情书的邮戳 2020-12-07 03:05

I have a TextBox in my form and I added this event on it:

private void txtValue_KeyDown(object sender, KeyEventArgs e)
        {
            Me         


        
2条回答
  •  北海茫月
    2020-12-07 03:51

    KeyDown and KeyUp use KeyEventArgs, which exposes the Keys enum via the KeyData property. The enum does not have representation for lower-case alphabetic values.

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

    The KeyPress event allows you to get the actual character of the key pressed via KeyPressEventArgs.KeyChar.

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

提交回复
热议问题