Matteo Figini
Matteo Figini

Reputation: 25

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?

Upvotes: 2

Views: 2849

Answers (1)

Robert
Robert

Reputation: 26

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

Upvotes: 1

Related Questions