Hi,
Here is some sample code on how to move a label and button. I
hope it helps. The label I add to the form with code and button I dropped
on the form in the designer.
Dim bMoving As Boolean = False
Dim WithEvents lbl As Label
Dim bMovelbl As Boolean = False
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
lbl = New Label
With lbl
.Location = New Point(10, 10)
.Text = "Move Me"
.BackColor = Color.Transparent
End With
Me.Controls.Add(lbl)
End Sub
Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
bMoving = True
End Sub
Private Sub Button1_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Button1.MouseMove
Static oldX, oldY As Integer
If bMoving Then
Button1.Location = New Point(Button1.Left + e.X - oldX,
Button1.Top + e.Y - oldY)
Else
oldX = e.X
oldY = e.Y
End If
End Sub
Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp
bMoving = False
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
MessageBox.Show(Button1.Location.ToString)
End Sub
Private Sub lbl_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lbl.MouseDown
bMovelbl = True
End Sub
Private Sub lbl_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lbl.MouseUp
bMovelbl = False
End Sub
Private Sub lbl_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lbl.MouseMove
Static oldX, oldY As Integer
If bMovelbl Then
lbl.Location = New Point(lbl.Left + e.X - oldX, lbl.Top + e.Y -
oldY)
Else
oldX = e.X
oldY = e.Y
End If
End Sub
Ken
-------------------------
"iwdu15" <iw****@discussions.microsoft.com> wrote in message
news:84**********************************@microsof t.com...
hi, im trying to egt a picturebox to follow the mousecursor around in a
certain area, but the picturebox isnt where the mouse is...how can i get
the
picturebox to be where the mouse cursor is? thanks
--
-iwdu15