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
mgmhicksAsked:
Who is Participating?
 
bobHackerConnect With a Mentor Commented:

Hello,

In the "Field"/control's exit event set up a variable with a value as to where you were.
Set the variable to the proper scope.
...then you will now where you came from.

b+  
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
You can use

Screen.PreviousControl.Name

mx
0
 
mgmhicksAuthor Commented:
receiving PreviousControl.name is not a member of screen.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
But it is ... seem image

something else is up

mx
Capture1.gif
0
 
kdwoodCommented:

I don't think he is in Access.  I believe he is in VB.NET

Regards,

Keith
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
mgmhicks,
What platform are you in?

mx
0
 
mgmhicksAuthor Commented:
This is what I see.
Sorry this is what I see.  Using VS 2008
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
You are not in Access.  I would move this Question to the VB.Net / VB zone.

I don't know the answer ... sorry.

mx
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Use a COMMON handler for ALL of your TextBoxes by listing them all after the "Handles" keyword.

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

Open in new window


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

Open in new window

0
 
mgmhicksAuthor Commented:
Ended up using lost focus event and using the tag property of the form to know what field to change.

thanks
0
All Courses

From novice to tech pro — start learning today.