Solved

How to determine last textbox with focus.

Posted on 2011-02-18
10
457 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:mgmhicks
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 75
ID: 34929399
You can use

Screen.PreviousControl.Name

mx
0
 

Author Comment

by:mgmhicks
ID: 34929429
receiving PreviousControl.name is not a member of screen.
0
 
LVL 75
ID: 34929482
But it is ... seem image

something else is up

mx
Capture1.gif
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:kdwood
ID: 34929527

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

Regards,

Keith
0
 
LVL 75
ID: 34929554
mgmhicks,
What platform are you in?

mx
0
 

Author Comment

by:mgmhicks
ID: 34929657
This is what I see.
Sorry this is what I see.  Using VS 2008
0
 
LVL 75
ID: 34929685
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
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 34929798
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
 
LVL 2

Accepted Solution

by:
bobHacker earned 500 total points
ID: 34929799

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
 

Author Closing Comment

by:mgmhicks
ID: 35012383
Ended up using lost focus event and using the tag property of the form to know what field to change.

thanks
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question