GotFocus Question


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: GotFocus Question

  1. #1
    Join Date
    Jul 2004
    Posts
    366

    Question GotFocus Question

    Ok,

    Is there a way to write code behind say 1 gotfocus of a textbox and have it affect all textboxs? If I have 20 textboxes on screen I dont want to have to put code in 20 places. Just 1 place. Is this possible?

    For example, if I want to change the background color of all the textboxes that have focus, without writing in the gotfocus of every textbox.

    Thanks in advance..

    jb

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Sure, just list all the textboxes in the event's Handles clause:
    Code:
        Private Sub TextBox_GotFocus(ByVal sender As Object, _ 
            ByVal e As System.EventArgs) Handles TextBox1.GotFocus, TextBox2.GotFocus ' , etc.
    A cleaner approach is to create a new class which inherits from TextBox and which overrides the OnGotFocus method with the desired code. Then, instead of using the standard TextBox control on your form, use the inherited class: http://forums.devx.com/showpost.php?...65&postcount=2
    Last edited by Phil Weber; 02-23-2007 at 06:24 PM.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Oct 2006
    Posts
    4
    geez that would have saved me some time...

  4. #4
    Join Date
    Jul 2004
    Posts
    366

    Smile Gotfocus Event

    Phil,

    That's what I was doing but I had my sub doing the wrong thing so it wasn't working. I figured it out and works fine.

    Thank you for your help.

    jb

Similar Threads

  1. Display one record at a time!
    By ASP learner in forum ASP.NET
    Replies: 5
    Last Post: 10-08-2002, 08:17 PM
  2. question on best programming option
    By James in forum .NET
    Replies: 2
    Last Post: 03-28-2002, 08:14 AM
  3. VB,STORED PROC, COM, DTC QUESTION?
    By melvin ng in forum VB Classic
    Replies: 1
    Last Post: 11-10-2000, 04:46 AM
  4. Closing Database Question
    By Kevin McGuire in forum VB Classic
    Replies: 1
    Last Post: 09-05-2000, 04:51 PM
  5. Performance question
    By John in forum VB Classic
    Replies: 2
    Last Post: 04-05-2000, 10:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center