Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4272254
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:33:10+00:00 2026-05-21T07:33:10+00:00

I have multiple textbox in a form. How do I know what textbox the

  • 0

I have multiple textbox in a form. How do I know what textbox the cursor currently is?
Trying to do something like this:

If TextBox2.Focus() = True Then
            MessageBox.Show("its in two")
        ElseIf TextBox3.Focus = True Then
            MessageBox.Show("its in three")
        End If

But I think its not working.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T07:33:11+00:00Added an answer on May 21, 2026 at 7:33 am

    Obviously, it will not work if you are calling your code in a Button_Click because when you click the Button then the focus is itself goes to the Button which you have clicked.

    You can do two things:

    Make a combined Focus event for all TextBoxes and check its Sender object.

    Private Sub TextBox_Focus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.Enter, TextBox3.Enter
        Dim currTextBox As TextBox = sender
    
        If currTextBox.Equals(TextBox2) Then
            MessageBox.Show("it's in two")
        ElseIf currTextBox.Equals(TextBox3) Then
            MessageBox.Show("it's in three")
        End If
    
    End Sub
    

    OR

    Take a global string variable, and set its value at each TextBox_Focus event, then check string value in the button click event.

     Dim str As String  
     Private Sub TextBox2_Focus(ByVal sender As System.Object, ByVal e As System.EventArgs)  Handles TextBox2.Enter
         str = "two"
     End Sub
    
     Private Sub TextBox3_Focus(ByVal sender As System.Object, ByVal e As System.EventArgs)  Handles TextBox3.Enter
         str = "three"
     End Sub
    
     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)  Handles Button1.Click
          MessageBox.Show("it's in " & str)
     End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got this HTML form where I have multiple input elements: text, radio, and
I have multiple textboxes in my form like txtTask0, txtTask1... txtTask12. so I want
I have form like this: <input type='text' name='people' id='namepeople'> <input type='hidden' name='idpeople' id='idpeople'> <input
i have a textbox on a form and i would like the user to
I am having a form in which I have multiple line textbox and status
I have a form with multiple textbox and combox .When I click save &
I have a Custom Control that has multiple textbox fields and a checkbox contained
I have multiple projects in a couple of different workspaces. However, it seems like
I have a form with multiple textboxes with the same names. I want to
I have a rails form that has a datetime input. I'd like to make

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.