|
-
Jul 13th, 2008, 01:24 PM
#1
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:
Private Sub tmrFocus_Timer()
Static PrevActiveCtl As Control
If Not (Me.ActiveControl Is PrevActiveCtl) Then
Set PrevActiveCtl = Me.ActiveControl
'Active Control Changed. Do your thing.
Else
'ActiveControl not changed. Do nothing
End If
End Sub
Can any one suggest me any better idea ?
.
-
Jul 13th, 2008, 03:11 PM
#2
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).
-
Jul 16th, 2008, 07:45 PM
#3
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|