|
-
Jan 13th, 2006, 12:17 PM
#1
Thread Starter
New Member
Make a button follow the mouse.
I am trying to make a button follow the mouse but with the code below the actual button is maybe about 2 inches off from the mouse's pointer. The
button is about 2 inches to the right and below of the cursor but it does follow around as intended, but for some reason when the form is maximised it is only about 1 inch to the right and 1 inch below the cursor.
VB Code:
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
Dim MouseX As Integer = Me.MousePosition.X
Dim MouseY As Integer = Me.MousePosition.Y
Me.btnRun.Location = New Point(MouseX, MouseY)
End Sub
Last edited by nclax99; Jan 13th, 2006 at 12:21 PM.
-
Jan 13th, 2006, 12:46 PM
#2
Frenzied Member
Re: Make a button follow the mouse.
I believe Me.MousePosition gives you the position of the mouse relative to the screen, while the button location is relative to it's container (i.e. the form, or a panel if the button is inside the panel). Use e to get the mouse corrdinates. That gives you the corrdinates relative to the container.
VB Code:
btnRun.Location = new point(e.x, e.y)
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
|