0

Greetings

I have a USB RFID scanner. While I have this form1 up, I want to send any keyboard input and put it in a textbox which is in another form(say form2). I tried using this code but to no avail. The first form is named "MainMenu".
Every time of a keypress, the the letter or digit input will go to another form. Is this even possible or am I just doing something wrong?

Private Sub MainMenu_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress

    Form2.Textbox1.text = e.KeyChar

End Sub
4
Contributors
4
Replies
6
Views
4 Years
Discussion Span
Last Post by Depreciated
0

You're on the right track. MainMenu can't have any control that will steal the focus. Setting Enabled property to false works. Also, setting all the tabstop properties to false will work.

Edited by tinstaafl

1

You could try setting the forms KeyPreview property to True. You'll have to do some pre-processing in one of the form's Key events (KeyDown, KeyPress, KeyUp) to ensure the characters are handled properly.

0

I may be old-school, but I like global variables for things like this. I think what I'd do is something like:

[frm1] gblVar = ""
[frm2] @ KeyPress event: gblVar &= e.keychar
then, when frm2.close
txtFld.text = gblVar

0

@Reverend Jim

setting the form's KeyPreview property to True worked like a charm. Whatever input I give can go to the other form without using the textbox. Now I just need the device and work on how to make the reader read multiple tags at once, having different separate inputs.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.