Results 1 to 3 of 3

Thread: Getting notification when Me.ActiveControl changes

  1. #1

    Thread Starter
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Arrow Getting notification when Me.ActiveControl changes

    I have multiple control in the form. 10+ textboxes, 2 listviews, 3 grids etc.

    Each one of them will do different things on GetFocus. The textboxes will change back color, the listview will highlight the related items and the grids will highlight active rows.

    I don't want to use control arrays and I don't want to write in multiple GotFocus/LostFocus. The only idea I have is, checking wheather Me.ActiveControl has changed or not from a timer.

    vb Code:
    1. Private Sub tmrFocus_Timer()
    2.     Static PrevActiveCtl As Control
    3.    
    4.     If Not (Me.ActiveControl Is PrevActiveCtl) Then
    5.         Set PrevActiveCtl = Me.ActiveControl
    6.         'Active Control Changed. Do your thing.
    7.     Else
    8.       'ActiveControl not changed. Do nothing
    9.     End If
    10. End Sub

    Can any one suggest me any better idea ?


    .
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  2. #2
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Getting notification when Me.ActiveControl changes

    All focus events in VB are handled by a hidden window, so you could subclass that to get notified each time focus changes. There is a window called VBFocus (VBFocusRT6 in runtime), which apparently handles all focus stuff. If I recall correctly, this is a child of ThunderMain/ThunderRT6Main and there is also VBBubble/VBBubbleRT6 which is a base class for all VB6 controls (or so I've read).

    Anyways, try to spy on those windows and see where the focus messages go, then try to subclass that. It is more complex than your current approach, but in the other hand you'd get instantly notified and it would be more lightweight (if done well).

  3. #3

    Thread Starter
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: Getting notification when Me.ActiveControl changes

    Thanks for the pointer to VBBubble/VBFocus. I've googled for them and found many links. I'll try to use it to trap focus-change event.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


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