|
-
Jun 27th, 2010, 08:11 PM
#1
Thread Starter
New Member
Getting Mouse Position over an Object
I am using VB.NET and I am currently having a problem accurately reading the mouse position. In my code, whenever the user moves the mouse, I want to have two variables store the mouse position's X and Y value, however when I move the mouse over an object such as a picturebox or a label, it will no longer give me the value until I move the pointer off the object onto the form. Are there any methods that will give me the absolute mouse coordinates regardless of whether the mouse is over an object or not?
-
Jun 27th, 2010, 08:19 PM
#2
Lively Member
Re: Getting Mouse Position over an Object
you could try this:
vb.net Code:
Dim mousePos As Point = MousePosition() Dim mousex As Integer = mousePos.X Dim mousey As Integer = mousePos.Y
-
Jun 27th, 2010, 09:22 PM
#3
Thread Starter
New Member
Re: Getting Mouse Position over an Object
Nope, sorry still doesn't work. I've tried:
e.x ; e.y
Cursor.Position.X - (Me.Location.X + 28) ; Cursor.Position.Y - (Me.Location.Y + 28)
and something else with PointToClient
-
Jun 27th, 2010, 09:27 PM
#4
Re: Getting Mouse Position over an Object
That makes it sound like you are getting something, just not what you want. I haven't specifically looked at this, but I would expect that you are getting the position in screen coordinates. Does that sound right? What happened when you used PointToClient from the form?
My usual boring signature: Nothing
 
-
Jun 27th, 2010, 09:42 PM
#5
Thread Starter
New Member
Re: Getting Mouse Position over an Object
In every case I got the same result. The program correctly returns the mouse coordinates UNLESS the pointer is hovering over an object, such as a button, label, picturebox, etc.
-
Jun 28th, 2010, 12:31 AM
#6
Re: Getting Mouse Position over an Object
It sounds like you're handling the MouseMove event of the form but not of the controls on the form. If you want to be able to track the mouse pointer over any control then you must handle the appropriate event of every control. You can use a single method and just add every control and the form to the Handles clause, which you can do in the Properties window.
-
Jun 28th, 2010, 10:27 AM
#7
Thread Starter
New Member
Re: Getting Mouse Position over an Object
Thank you. I have almost solved my problem now. I know have the mouse moving correctly over the picture boxes, however I am still encountering one problem. Since I have initialized an array of pictureboxes at runtime, how would I go about adding those to the Handle clause? It does not simply let me add Grid().MouseMove, or anything like that.
-
Jun 28th, 2010, 04:57 PM
#8
Re: Getting Mouse Position over an Object
When you add items to the list, you will have to add the handler directly with:
AddHandler <event you want to handle>,AddressOf <Sub that handles the event>
My usual boring signature: Nothing
 
-
Jun 28th, 2010, 07:06 PM
#9
Re: Getting Mouse Position over an Object
Just be sure that, for every AddHandler, there's a corresponding RemoveHandler when you're done with the object.
-
Jun 28th, 2010, 08:36 PM
#10
Thread Starter
New Member
Re: Getting Mouse Position over an Object
All right then, one more thing and then I'll be all good. Now it successfully detects mouse movement over all parts of the image, however, when it returns the mouse coordinates, it does it relative to whatever object the mouse is hovering over. Is there anyway for it to consistently return the mouse coordinates relative to the frame all the time?
edit: Shell yeah, never mind I gots this one, I just replaced that e.X thing I had with the other thing involving Cursor.Position.X that I had earlier, awesum then, thanks SHOO MUCHHH guys DDD
Last edited by ducko; Jun 28th, 2010 at 08:48 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|