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(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
lbl = New Label
With lbl
.Location = New Point(10, 10)
.Text = "Move Me"
.BackColor = Color.Transpare nt
End With
Me.Controls.Add (lbl)
End Sub
Private Sub Button1_MouseDo wn(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles Button1.MouseDo wn
bMoving = True
End Sub
Private Sub Button1_MouseMo ve(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles Button1.MouseMo ve
Static oldX, oldY As Integer
If bMoving Then
Button1.Locatio n = New Point(Button1.L eft + 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.MouseEven tArgs) Handles Button1.MouseUp
bMoving = False
End Sub
Private Sub Button1_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles Button1.Click
MessageBox.Show (Button1.Locati on.ToString)
End Sub
Private Sub lbl_MouseDown(B yVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles lbl.MouseDown
bMovelbl = True
End Sub
Private Sub lbl_MouseUp(ByV al sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles lbl.MouseUp
bMovelbl = False
End Sub
Private Sub lbl_MouseMove(B yVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) 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****@discuss ions.microsoft. com> wrote in message
news:84******** *************** ***********@mic rosoft.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