Results 1 to 6 of 6

Thread: Control, Gotfocus

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 1999
    Location
    Ruinen, Drente, Netherlands
    Posts
    192

    Control, Gotfocus

    How can I see if a Control on the form gets the Focus (GotFocus) AND what Control that is (Control.name) ?

  2. #2
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    Read help on ActiveControl.

  3. #3
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Control, Gotfocus

    Originally posted by Kars Lensen
    How can I see if a Control on the form gets the Focus (GotFocus) AND what Control that is (Control.name) ?
    you could put code in the gotfocus event of the control you are working with..

  4. #4
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    VB Code:
    1. Me.ActiveControl

    Depending upon what you are trying to do, you can use this in a global sub...

    I use it to change the backcolor of the control which receives focus...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Apr 1999
    Location
    Ruinen, Drente, Netherlands
    Posts
    192
    Thanks all, I now I can do it in the Gotfocus event but I wil do that only once in the form (or the project ...), James can you give an example ?

  6. #6
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Very simple example :

    VB Code:
    1. ' ON GOT FOCUS EVENT ON CERTAIN CONTROLS
    2.  
    3. Function YELLOWGOTFOCUS(GETCONTROL As Control)
    4.  
    5.     On Error Resume Next
    6.    
    7.     If TypeOf GETCONTROL Is TextBox Then
    8.    
    9.         GETCONTROL.BackColor = vbYellow
    10.        
    11.         GETCONTROL.ForeColor = vbRed
    12.        
    13.         GETCONTROL.SelStart = 0
    14.        
    15.         GETCONTROL.SelLength = Len(GETCONTROL)
    16.            
    17.     ElseIf TypeOf GETCONTROL Is ComboBox Then
    18.    
    19.         GETCONTROL.BackColor = vbYellow
    20.        
    21.         GETCONTROL.ForeColor = vbRed
    22.        
    23.     End If
    24.  
    25. End Function
    26.  
    27. ' ON LOST FOCUS OF CERTAIN CONTROLS
    28.  
    29. Function WHITELOSTFOCUS(GETCONTROL As Control)
    30.  
    31.     If TypeOf GETCONTROL Is TextBox Then
    32.    
    33.         GETCONTROL.BackColor = vbWhite
    34.        
    35.         GETCONTROL.ForeColor = vbBlack
    36.        
    37.     ElseIf TypeOf GETCONTROL Is ComboBox Then
    38.    
    39.         GETCONTROL.BackColor = vbWhite
    40.        
    41.         GETCONTROL.ForeColor = vbBlack
    42.            
    43.     End If
    44.  
    45. End Function

    If you add this code to a module, you can access from anywhere inside your project...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width