By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,712 Members | 1,447 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,712 IT Pros & Developers. It's quick & easy.

Determine the Control under the mouse cursor

P: n/a
How can I determine the control under the mouse cursor when a user
muves the mouse?? For example if the user moves the cursor over a
textbox i would receive the name of that textbox without using the
"MouseMove" event for that textbox.

Thanks

Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies

P: n/a
"Andrea V.F." <vf******@gmail.com> schrieb:
How can I determine the control under the mouse cursor when a user
muves the mouse?? For example if the user moves the cursor over a
textbox i would receive the name of that textbox without using the
"MouseMove" event for that textbox.


Take a look at the form's 'GetChildAtPoint' method. You can determine the
current cursor position using 'Cursor.Position'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #2

P: n/a
Your suggestion works if a component is on a Form, but not if the
component is on a Panel (as in my case).

Thanks for help.

Nov 21 '05 #3

P: n/a


Andrea V.F. wrote:
Your suggestion works if a component is on a Form, but not if the
component is on a Panel (as in my case).


If the control returned from Form.GetControlAtPoint is a container
control, then you need to call *its* GetControlAtPoint method, and so
on recursively until you end up with a control that isn't a container,
or Nothing, which means you are on a blank part of the container. Make
sure to transform your Point appropriately on the way down.

It might be easier to hook up all your form's controls' MouseMove event
to a single event handler.

--
Larry Lard
Replies to group please

Nov 21 '05 #4

P: n/a
if I call the GetControlAtPoint of the panel I receive always Nothing
even if I'm on a control into the panel.

What do you mean with "Make
sure to transform your Point appropriately on the way down."

Nov 21 '05 #5

P: n/a
"Andrea V.F." <vf******@gmail.com> schrieb:
if I call the GetControlAtPoint of the panel I receive always Nothing
even if I'm on a control into the panel.

What do you mean with "Make
sure to transform your Point appropriately on the way down."


'Control.PointToClient' et al. The control's 'GetControlAtPoint' method
expects control coordinates, not screen coordinates.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #6

P: n/a


Herfried K. Wagner [MVP] wrote:
"Andrea V.F." <vf******@gmail.com> schrieb:
if I call the GetControlAtPoint of the panel I receive always Nothing
even if I'm on a control into the panel.

What do you mean with "Make
sure to transform your Point appropriately on the way down."


'Control.PointToClient' et al. The control's 'GetControlAtPoint' method
expects control coordinates, not screen coordinates.


I was gonna say that and I had a nice sample ready, but my sample
doesn't work! I have a nice recursive routine that takes screen
coordinates and returns the control in that position - BUT - when do I
call it? Form.MouseMove is no use as it isn't called when not
*directly* on the form; and I think we wanted to avoid hooking to every
MouseMove event?

Confused.

--
Larry Lard
Replies to group please

Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.