|
-
Jun 24th, 2006, 11:12 AM
#1
Thread Starter
Lively Member
[RESOLVED] Relative to container not screen
I have a panel that is called "Self" and I would like to make it follow the exact mouse movements.
I have done this. However it is not centred with the mouse and is reliant upon where the form is located on the screen. I don't want this.
VB Code:
Private Sub Self_FollowMouse_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Self_FollowMouse.Tick
X = Control.MousePosition.X
Y = Control.MousePosition.Y
Self.Location = New Point(X - 5, Y - 5)
End Sub
How do I solve this problem. thanks.
Last edited by emdiesse; Jun 24th, 2006 at 11:36 AM.
Emdiesse
-
Jun 24th, 2006, 12:38 PM
#2
Re: Relative to container not screen
Control.MousePosition returns a point relative to the screen.
To get the position of the mouse relative to your form, you need to convert this point by using the PointToClient method.
VB Code:
Private Sub Self_FollowMouse_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Self_FollowMouse.Tick
Dim p As Point = PointToClient(Control.MousePosition)
X = p.X
Y = p.Y
Self.Location = New Point(X - 5, Y - 5)
End Sub
-
Jun 24th, 2006, 12:58 PM
#3
Thread Starter
Lively Member
Re: Relative to container not screen
 Originally Posted by Andy_P
Control.MousePosition returns a point relative to the screen.
To get the position of the mouse relative to your form, you need to convert this point by using the PointToClient method.
VB Code:
Private Sub Self_FollowMouse_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Self_FollowMouse.Tick
Dim p As Point = PointToClient(Control.MousePosition)
X = p.X
Y = p.Y
Self.Location = New Point(X - 5, Y - 5)
End Sub
Thank you.
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
|