467,877 Members | 1,135 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Mouse Movement & Control Bounds

Tom
Hi

I am having problems working out if the mouse pointer is within the
control bounds within the OnMouseMove method:

Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)

Debug.WriteLine(Me.Bounds.Contains(e.X, e.Y))

End Sub

This always returns false even when the mouse is being moved over the
control. I would expect it only to return false if the mouse was being
moved outside the control when the mouse button was originally pressed
over the control.

MSDN suggests that i am using it correctly:

http://msdn.microsoft.com/library/de...ainstopic1.asp

Anyone know where i am going wrong?

Thanks

Tom
Nov 20 '05 #1
  • viewed: 2526
Share:
8 Replies
"Tom" <re***@to.group> schrieb
Hi

I am having problems working out if the mouse pointer is within
the control bounds within the OnMouseMove method:

Protected Overrides Sub OnMouseMove(ByVal e As
MouseEventArgs)

Debug.WriteLine(Me.Bounds.Contains(e.X, e.Y))

End Sub

This always returns false even when the mouse is being moved over
the control. I would expect it only to return false if the mouse was
being moved outside the control when the mouse button was originally
pressed over the control.

MSDN suggests that i am using it correctly:

http://msdn.microsoft.com/
library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdr
awingrectangleclasscontai nstopic1.asp

Anyone know where i am going wrong?


Bounds returns coordinates relative to the parent of the control, whereas
e.x and e.y are relative to the top left corner of the control.

Use
Debug.WriteLine(Me.ClientRectangle.Contains(e.X, e.Y))

BTW, don't forget to call
MyBase.OnMouseMove(e)
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
Nov 20 '05 #2
Tom
>On Thu, 20 May 2004 13:21:00 +0200, "Armin Zingler" <az*******@freenet.de> wrote:
Bounds returns coordinates relative to the parent of the control, whereas
e.x and e.y are relative to the top left corner of the control.

Use
Debug.WriteLine(Me.ClientRectangle.Contains(e.X, e.Y))

BTW, don't forget to call
MyBase.OnMouseMove(e)


Armin, that's fantastic, thanks mate.
Nov 20 '05 #3
* Tom <re***@to.group> scripsit:
I am having problems working out if the mouse pointer is within the
control bounds within the OnMouseMove method:

Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)

Debug.WriteLine(Me.Bounds.Contains(e.X, e.Y))

End Sub

This always returns false even when the mouse is being moved over the
control. I would expect it only to return false if the mouse was being


Mouse events will only be generated for the control under the mouse, so
you won't receive an event when the mouse is moved outside the control.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #4
Tom
On 20 May 2004 16:16:47 +0200, hi***************@gmx.at (Herfried K.
Wagner [MVP]) wrote:
* Tom <re***@to.group> scripsit:
I am having problems working out if the mouse pointer is within the
control bounds within the OnMouseMove method:

Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)

Debug.WriteLine(Me.Bounds.Contains(e.X, e.Y))

End Sub

This always returns false even when the mouse is being moved over the
control. I would expect it only to return false if the mouse was being


Mouse events will only be generated for the control under the mouse, so
you won't receive an event when the mouse is moved outside the control.


If the mouse button is pressed over the control and remains pressed as
you move off the control, the event will still fire as the mouse
moves, likewise the OnMouseUp event.
Nov 20 '05 #5
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schrieb
This always returns false even when the mouse is being moved over
the control. I would expect it only to return false if the mouse
was being


Mouse events will only be generated for the control under the mouse,
so you won't receive an event when the mouse is moved outside the
control.

No, it is also received outside as stated in the sentence you quoted only
the first half. ;-)

"I would expect it only to return false if the mouse was being
moved outside the control when the mouse button was originally pressed
over the control."
--
Armin

Nov 20 '05 #6
* Tom <re***@to.group> scripsit:
This always returns false even when the mouse is being moved over the
control. I would expect it only to return false if the mouse was being


Mouse events will only be generated for the control under the mouse, so
you won't receive an event when the mouse is moved outside the control.


If the mouse button is pressed over the control and remains pressed as
you move off the control, the event will still fire as the mouse
moves, likewise the OnMouseUp event.


OK, I didn't think of that. Thank you for making me aware that I missed
this case.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #7
* "Armin Zingler" <az*******@freenet.de> scripsit:
No, it is also received outside as stated in the sentence you quoted only
the first half. ;-)

"I would expect it only to return false if the mouse was being
moved outside the control when the mouse button was originally pressed
over the control."


Sorry :-(. I took 13 hours of sleep but I am still tired...

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #8
We see it, however now I know I will have patience

Cor

Sorry :-(. I took 13 hours of sleep but I am still tired...

Nov 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by BadOmen | last post: by
1 post views Thread by Benny Raymond | last post: by
3 posts views Thread by Morten Snedker | last post: by
reply views Thread by jack112 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.