J
John Wright
I am reading data from a serial port using the DataReceived event from the
COM control. I need to check which text box has the focus on the form so I
can call the right function. As you can see in my code below I want to
check for the focus. The problem I have is I get a cross thread error when
trying to do this. Is there any way to modify this code so I can check
which control has focus so I can call the right function? Since it is
possible on the form to have move than one item receive data from COM 1 (a
digital scale), I need to know which weight they are sending. Any help is
much appreciated.
John Wright
Code:
Private Sub SerialTare_DataReceived(ByVal sender As Object, ByVal e As
System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialTare.DataReceived
'check which textbox has the focus and then call the right method
If txtTareWeight.Focus = True Then
'check the tare weight field. If there is something there than add the data
to the run weight
txtTareWeight.Invoke(New myDelegate(AddressOf GetTransferWeight))
ElseIf txtEvalWeight.Focus = True Then
txtEvalWeight.Invoke(New myDelegate(AddressOf GetTransferWeight))
End If
End Sub
COM control. I need to check which text box has the focus on the form so I
can call the right function. As you can see in my code below I want to
check for the focus. The problem I have is I get a cross thread error when
trying to do this. Is there any way to modify this code so I can check
which control has focus so I can call the right function? Since it is
possible on the form to have move than one item receive data from COM 1 (a
digital scale), I need to know which weight they are sending. Any help is
much appreciated.
John Wright
Code:
Private Sub SerialTare_DataReceived(ByVal sender As Object, ByVal e As
System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialTare.DataReceived
'check which textbox has the focus and then call the right method
If txtTareWeight.Focus = True Then
'check the tare weight field. If there is something there than add the data
to the run weight
txtTareWeight.Invoke(New myDelegate(AddressOf GetTransferWeight))
ElseIf txtEvalWeight.Focus = True Then
txtEvalWeight.Invoke(New myDelegate(AddressOf GetTransferWeight))
End If
End Sub