保留文本框中的值

时间:2019-04-12 01:14:18

标签: vb.net

美好的一天!我在保留文本框中的数据时遇到问题。轻按RFID卡后,它消失几秒钟。我正在使用serialport连接arduino + rfid。我在Timer1的操作上遇到了困难。

我尝试更改了timer1的间隔时间,但它只影响读卡的延迟。

这里是代码:

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        receivedData = ReceiveSerialData()
        rfidd.Text = receivedData

    End Sub

从recevedData到rfidd.text的值不会重置为“”

1 个答案:

答案 0 :(得分:0)

我在C#中找到了解决方案 这里是链接: How to display data received from serial port in a textbox without the text disappearing in Visual Studio C#?

我对VB可以理解的代码所做的改动很小:


Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        receivedData = ReceiveSerialData()
        ' rfidd.Text = receivedData


        If (rfidd.Text IsNot receivedData) Then ' Only Then Update If temperature Is different

            Try

                rfidd.AppendText(Environment.NewLine)
                rfidd.AppendText(receivedData)

            Catch ex As NullReferenceException

            End Try


        End If


    End Sub