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 9121965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:58:53+00:00 2026-06-17T05:58:53+00:00

I got many textboxes (about 10) in a form. I want the text in

  • 0

I got many textboxes (about 10) in a form. I want the text in the textbox to be higlighted whenever it gets foucs. The code for that looks like:

Private Sub txtBillNo_GotFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtBillNo.GotFocus
   HoverText(txtBillNo)
End Sub

Private Sub HoverText(ByRef ctrl as TextBox)
   ctrl.SelectAll()
End Sub

It works perfectly, but I though I could do some code optimization here. Since, I have about 10 textboxes (and many other forms containing several textboxes), I have to HoverText(TextBox) in every Private Sub.. Handles TextBox.GotFocus for every textbox in each form.

I look for any form event (or any other way) that is trigerred when focus is given to another control (textbox) within the form, either by MouseClick or TAB so that HoverText(TextBox) is needed to be written only once for a form.

  • 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-06-17T05:58:54+00:00Added an answer on June 17, 2026 at 5:58 am

    You can list all your textboxes in the Handles clause:

    Private Sub atextbox_GotFocus(ByVal sender As System.Object, ByVal e As _
     System.EventArgs) _
               Handles txt1.GotFocus, _
                       txt2.GotFocus, _
                       txt3.GotFocus, _
                       (...remaining text boxes..)
                       txt9.GotFocus, _
                       txt10.GotFocus
    

    Or you can add handlers to all textboxes when loading the form:

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        For Each t In Me.Controls.OfType(Of TextBox)()
            AddHandler t.GotFocus, AddressOf HoverText
        Next
    End Sub
    
    Private Sub HoverText(ByVal sender As System.Object, ByVal e As System.EventArgs)
        DirectCast(sender, TextBox).SelectAll()
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ive got a Form application in VB.NET. I have many text boxes on one
In many tutorial of Acl component in cakephp i got instruction that add component
I got many panels and one form. I have employed panels so I don't
I got many .dll files for my project. It is quite troublesome that moving
I've got many objects that structures aren't the same. But I know that all
I've got many, many mp3 files that I would like to merge into a
Hy, suppose you got many files in a folder and you want first to
I've got many files with variables in them like {$var1} some text {$var2} some
I've written a Form object (code: http://pastebin.com/U1xMRhdn ) that validates whether information entered in
I got many qtips in a form with lets like this : $('.selector').qtip({ content:

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.