简体   繁体   中英

Get ASCII character code from a KeyDown in Visual Basic .NET

I was trying to make a Visual Basic .NET program that shows, when a key is down, a MsgBox with the code of the key pressed: the problem is that the program read a lowercase letter (for example, 'a') as the same of the corresponding uppercase letter (for example, 'A').

This is the code in VB .NET, Framework 4.6.1:

Public Class Form1
    Dim character As String
    Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
        MsgBox(e.KeyCode, MsgBoxStyle.Information)
    End Sub
End Class

How can I read a lowercase letter and the corresponding uppercase letter in two different numbers?

To illustrate Hans comment:

Private Sub TextBox1_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
    Dim msg As String = String.Format("You pressed: {0}", e.KeyChar.ToString)
    MessageBox.Show(msg)
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM