By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,784 Members | 1,239 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,784 IT Pros & Developers. It's quick & easy.

Check focus of text box

P: n/a
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
Jun 27 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
You have to invoke SerialTare_DataReceived

I usually have a line that says:

if me.InvokeRequired then
'Use delegate to invoke sub
else
'do work
end sub
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.