Retrieve of the control's name that the cursor is upon

carpeneda

Carpeneda
Local time
Today, 20:51
Joined
Mar 5, 2009
Messages
9
Hi,
After releasing a 'MouseMove' event, I'd like to read out the name or ID of the control or section, the cursor is in.
Thank you for any idea how to solve this problem.
E.G.
 
Something like the following may give you a jump start on figuring something out:

Code:
Dim ctlCurrentControl As Control

Set ctlCurrentControl = Screen.ActiveControl

MsgBox ctlCurrentControl.Name
 
You might find it useful to use the 'tag' property of the controls here - because you can assign arbitrary string values to them - which should make it easier to write a single-purpose function.

For example, although the names of pages in a tab control don't change when you amend their order, it's easier to deal with them by some sort of friendly name, hidden from the user - and the tag property is exactly that.

So (based on Ken's example):

Dim ctlCurrentControl As Control

Set ctlCurrentControl = Screen.ActiveControl

MsgBox ctlCurrentControl.Tag
 
Hello,
thank you for this quick reply.
But your proposition with screen.activeControl returns the control object that currently has the focus.
I need the name of the control, that has sent the MouseMove Event without having the focus.
For instance:
- Focus is at contr1.
- I move the mouse to contr2, without click.
- contr2 has a MouseMove event routine that should return the object of contr2
- I'd like to read the name (or other properties) of control2 into a variable.

Thanks & regards E.G.
 
If it's a one-off thing, you could just set the variable in the mousemove event...

But if you need to code for more than one control, take look at ChrisO's Soft-coding event handlers to funnel all controls' MouseMove event into a common procedure, passing the name if needed.
 

Users who are viewing this thread

Back
Top Bottom