在文本框更改时触发事件的最佳方法
我有一个usb mifare读卡器,它在出示卡片时充当键盘并吐出一个10位数字。
所以说我有一个文本框作为默认选择的控件用户将卡放在阅读器上并将数字读入文本框
我要做的是有一个隐藏的控件,一旦读取10位数就会触发事件。
奇怪的是我曾经有过一次这样的工作!
我尝试了什么:
这等待更多输入: -
I have a usb mifare card reader, which when presenting a card acts as a keyboard and spits out a 10 digit number.
So say I have a text box as the default selected control a user puts the card on the reader and the number is read into the textbox
What I'm trying to do is have a hidden control that fires off an event once the 10 digits are read.
Weird thing is I've had this working once!
What I have tried:
This just waits for more input :-
Private Sub TextBox1_Leave(sender As System.Object, e As System.EventArgs) Handles TextBox1.Leave
msgbox(textbox1.text.tostring)
End Sub
'This just reads the first character
Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged
MsgBox(TextBox1.Text.ToString)
End Sub
想想我可能用计时器解决了它 - 看起来好吗?我更喜欢隐藏它,目前有一个带闪烁光标的文本框
Think I may have solved it with a timer - does this look okay ? I'd prefer it to be hidden though, currently there's a text box with a flashing cursor
Private Sub rfidbox_textchanged(sender As System.Object, e As System.EventArgs) Handles rfidbox.TextChanged
Timer1.Stop()
Timer1.Start()
End Sub
勾选活动
Tick event
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
Timer1.Stop()
cardnumber = rfidbox.Text.ToString
Dim name As String
Dim x As New signclass
If rfidbox.Text = "" Then
Else
name = x.getnamefromcard(rfidbox.Text.ToString)
MsgBox(name)
rfidbox.Text = ""
End If
想想我用你的指针修复了它(USB rea输入后输入)
Think I fixed it with this thanks to your pointer (The USB reader enters after input)
Private Sub rfidinput_keypress(sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles rfidinput.KeyPress
If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then
Dim name As String
Dim x As New signclass
If rfidinput.Text = "" Then
Else
name = x.getnamefromcard(rfidinput.Text.ToString)
MsgBox(name)
rfidinput.Text = ""
End If
End If
End Sub
通过在按下其他元素时重新聚焦来保持对文本框的关注
I maintain focus on the textbox by refocusing when other elements are pressed