467,876 Members | 1,129 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,876 developers. It's quick & easy.

Obtaining control under mouse

Hello Group

In the old days i'ev created a VB6 appl. that was able to obtain the
underlaying control under the mouse pointer. I would very much like to do
that in a C# application. I'll use VS2005 and .Net 2.0

I'll know of the solution to code each control for the mouse over event, but
I cant use that i this case.

Any one outthere with som examples?

Kind regards
Johnny Jensen
Nov 14 '06 #1
  • viewed: 11433
Share:
4 Replies
"Johnny Jensen" <je*@aaa.dkwrote in message
news:uK**************@TK2MSFTNGP03.phx.gbl...
Hello Group

In the old days i'ev created a VB6 appl. that was able to obtain the
underlaying control under the mouse pointer. I would very much like to do
that in a C# application. I'll use VS2005 and .Net 2.0

I'll know of the solution to code each control for the mouse over event,
but I cant use that i this case.

Any one outthere with som examples?
interate through the controls collection and attach the mousemove event for
every control and then use Control.GetChildAtPoint in the event to find the
control the mouse it over.

Michael
Nov 14 '06 #2
Hey Michael

Thanks for replying and it gave me some hint, but mabye i'am a bit slow
here.

Say that i'll have a label control on my form in the rectangle 20,20,120,36
on the forms mousemove event I read the x any y values to get the point, but
the secund i reach the label the forms mousemove no longer runs - now it is
the labels mousemove event that runs, and the reading of x,y will now be
wrong.

So that way i'll never get the Control.GetChildAtPoint to be anything else
but null. but if i'll in the forms mousemove event get the x,y and look at
x+1,y-1 ( or something like that ) i'll get the control when i'am almost
over the label.

Could you give me some more hints?

Kind regards
Johnny Jensen
"Michael C" <no****@nospam.comwrote in message
news:eJ**************@TK2MSFTNGP04.phx.gbl...
"Johnny Jensen" <je*@aaa.dkwrote in message
news:uK**************@TK2MSFTNGP03.phx.gbl...
>Hello Group

In the old days i'ev created a VB6 appl. that was able to obtain the
underlaying control under the mouse pointer. I would very much like to do
that in a C# application. I'll use VS2005 and .Net 2.0

I'll know of the solution to code each control for the mouse over event,
but I cant use that i this case.

Any one outthere with som examples?

interate through the controls collection and attach the mousemove event
for every control and then use Control.GetChildAtPoint in the event to
find the control the mouse it over.

Michael

Nov 15 '06 #3

"Johnny Jensen" <je*@aaa.dkwrote in message
news:ec**************@TK2MSFTNGP06.phx.gbl...
Hey Michael

Thanks for replying and it gave me some hint, but mabye i'am a bit slow
here.

Say that i'll have a label control on my form in the rectangle
20,20,120,36 on the forms mousemove event I read the x any y values to get
the point, but the secund i reach the label the forms mousemove no longer
runs - now it is the labels mousemove event that runs, and the reading of
x,y will now be wrong.

So that way i'll never get the Control.GetChildAtPoint to be anything else
but null. but if i'll in the forms mousemove event get the x,y and look at
x+1,y-1 ( or something like that ) i'll get the control when i'am almost
over the label.

Could you give me some more hints?
You can do:

MouseMove += Form_MouseMove;
foreach (Control c in Controls)
c.MouseMove += Form_MouseMove;

then in
void Form_MouseMove(object sender, MouseEventArgs e)
sender is the control beneath the mouse (you can surely cast it to Control),
and e will contain the relative coordinates to the upper left of sender.
>
Kind regards
Johnny Jensen
"Michael C" <no****@nospam.comwrote in message
news:eJ**************@TK2MSFTNGP04.phx.gbl...
>"Johnny Jensen" <je*@aaa.dkwrote in message
news:uK**************@TK2MSFTNGP03.phx.gbl...
>>Hello Group

In the old days i'ev created a VB6 appl. that was able to obtain the
underlaying control under the mouse pointer. I would very much like to
do that in a C# application. I'll use VS2005 and .Net 2.0

I'll know of the solution to code each control for the mouse over event,
but I cant use that i this case.

Any one outthere with som examples?

interate through the controls collection and attach the mousemove event
for every control and then use Control.GetChildAtPoint in the event to
find the control the mouse it over.

Michael


Nov 15 '06 #4
"Johnny Jensen" <je*@aaa.dkwrote in message
news:ec**************@TK2MSFTNGP06.phx.gbl...
So that way i'll never get the Control.GetChildAtPoint to be anything else
but null. but if i'll in the forms mousemove event get the x,y and look at
x+1,y-1 ( or something like that ) i'll get the control when i'am almost
over the label.

Could you give me some more hints?
In addition to what Ben said, you should add label1.x and label1.y to your x
and y values.

Michael
Nov 19 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Andrew Grothe | last post: by
4 posts views Thread by simo | last post: by
reply views Thread by Qwert | last post: by
3 posts views Thread by blue_nirvana | last post: by
3 posts views Thread by Wayne Wengert | last post: by
2 posts views Thread by ahmed.maryam | last post: by
10 posts views Thread by Glich | last post: by
1 post views Thread by RobcPettit | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.