mgmhicks
asked on
How to determine last textbox with focus.
I have a form that looks like a keyboard, on the form is about 3 panels. Depending on what the user is doing determines what panel is visible and then, what textboxes are available. The idea being hit clicks on name text field lets say, and then hits the a, b,c, etc... on the keyboard. I need to know what field he just came from so I know what fields to put the keyboard items into. I hope that makes sense.
thanks
thanks
ASKER
receiving PreviousControl.name is not a member of screen.
I don't think he is in Access. I believe he is in VB.NET
Regards,
Keith
mgmhicks,
What platform are you in?
mx
What platform are you in?
mx
You are not in Access. I would move this Question to the VB.Net / VB zone.
I don't know the answer ... sorry.
mx
I don't know the answer ... sorry.
mx
Use a COMMON handler for ALL of your TextBoxes by listing them all after the "Handles" keyword.
Something like:
Note that if your buttons have the Text to be inserted as the caption of the button, AND all of the buttons do the exact same thing, then you can make all of them fire the same handler in the same way as the TextBoxes above:
Something like:
Public Class Form1
Private LastTextBox As TextBox = Nothing
Private Sub TB_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.GotFocus, TextBox2.GotFocus, TextBox3.GotFocus
LastTextBox = DirectCast(sender, TextBox)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Not IsNothing(LastTextBox) Then
LastTextBox.SelectedText = Button1.Text
End If
End Sub
End Class
Note that if your buttons have the Text to be inserted as the caption of the button, AND all of the buttons do the exact same thing, then you can make all of them fire the same handler in the same way as the TextBoxes above:
Private Sub Btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click, Button3.Click
If Not IsNothing(LastTextBox) Then
Dim btn As Button = DirectCast(sender, Button)
LastTextBox.SelectedText = btn.Text
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ended up using lost focus event and using the tag property of the form to know what field to change.
thanks
thanks
Screen.PreviousControl.Nam
mx