TSFLLC
asked on
Respond to ANY mouse event ANYWHERE on a form with ONE sub routine
I need to respond to a mouse click anywhere on a form. I'm incorporating this into about 25 forms. I would like to create a sub routine that allows me to just paste into each one of them without having to customize for each form based on particulars of each form.
I've tried me.mousedown, me.click, mybase.click, mybase.mousedown
I have several group boxes on the form and I get no result when clicking anywhere inside the group boxes, but if I click outside of the group boxes mybase and me.click or .mousedown execute. Also, any of these forms may have text boxes, combo boxes, listviews, etc.
Is there ONE event that captures for any and all mouse activity throughout a form?
Phil Tate
I've tried me.mousedown, me.click, mybase.click, mybase.mousedown
I have several group boxes on the form and I get no result when clicking anywhere inside the group boxes, but if I click outside of the group boxes mybase and me.click or .mousedown execute. Also, any of these forms may have text boxes, combo boxes, listviews, etc.
Is there ONE event that captures for any and all mouse activity throughout a form?
Phil Tate
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In VB.NET, I would agree with newyuppie, only adding that you will need to make your code recursive because you have textboxes (etc.) within controls (e.g. groupboxes). Something like this (not tested).
Private Sub AddMouseHandler (ByVal ctl As Control)
If ctl.HasChildren Then
AddMouseHandler(ctl)
End If
addhandler ctl.mousedown, address of AllMouseDown
Exit Sub
called in Load event like this
for each ctl as control in me.controls
AddMouseHandler(ctl)
next ctl
Roger