I wouldnt advice you to do it that way. You'd need the user to know the exact format of the enum name member in order to set a key. Instead, make use of the fact that when the user presses a key in the textbox, you'll be able to get its Keys-enumeration value. Here's an example:
By handling the KeyPress event and setting e.Handled to true, we assure ourselves that the user can not enter anything by themselves into the textbox. And by handling the KeyUp event we can capture the pressed key and assign it to the myKey variable AND display it in the textbox.VB.NET Code:
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress e.Handled = True End Sub Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp myKey = e.KeyCode TextBox1.Text = myKey.ToString() End Sub




Reply With Quote