Keyboard assignments

  • Thread starter Thread starter Jon Cosby
  • Start date Start date
J

Jon Cosby

I'm trying to assign keys to a textbox. I've added a handler just for that
control. When I hit the keys, though, the values are entered in the active
textbox, not the one they're assigned to. Why is this?

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

AddHandler tb.KeyPress, AddressOf keypressed
End Sub

Private Sub keypressed(ByVal o As Object, ByVal e As KeyPressEventArgs)
If e.KeyChar = Microsoft.VisualBasic.ChrW(48) Then
e.Handled = True
ElseIf e.KeyChar = Microsoft.VisualBasic.ChrW(49) Then
e.Handled = True
...
tb.Text += e.KeyChar.ToString()
End Sub
 
I guess that was dumb, but the key assignments only work when the assigned
textbox is the active control. E.g., if I tab to a button, the key values do
not display.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top