在文本框更改时触发事件的最佳方法 [英] Best way to fire event on text box change

查看:99
本文介绍了在文本框更改时触发事件的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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


这篇关于在文本框更改时触发事件的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆