[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to determine last textbox with focus.

Posted on 2011-02-18
10
Medium Priority
?
464 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

656 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