Basta adicionar;
1:
Dim
NewPoint
As Point
2:
Private Sub
Form1_MouseDown(
ByVal
sender
As Object
,
ByVal
e
As MouseEventArgs
)
Handles
Me
.MouseDown 3:
If
MouseButtons <> Windows.Forms.MouseButtons.Left
Then
Exit Sub
4: NewPoint.X = Me.Left - MousePosition.X 5: NewPoint.Y = Me.Top - MousePosition.Y 6:
End Sub
7:
Private Sub
Form1_MouseMove(
ByVal
sender
As Object
,
ByVal
e
As
MouseEventArgs)
Handles
Me
.MouseMove 8:
If
MouseButtons <> Windows.Forms.MouseButtons.Left
Then Exit Sub
9: Me.Left = NewPoint.X + MousePosition.X 10: Me.Top = NewPoint.Y + MousePosition.Y 11:
End Sub
Neste código estamos movendo o form1 a partir dele mesmo, para mover por exemplo a partir de uma PictureBox, basta mudar
Handles
Me
.MouseMove
para Handles
PictureBox1
.MouseMove
e Handles
Me
.MouseDown
para Handles
PictureBox1
.MouseDown
ficaria assim;1:
Dim
NewPoint
As Point
2:
Private Sub
PictureBox1_MouseDown(
ByVal
sender
As Object
,
ByVal
e
As MouseEventArgs
)
Handles
PictureBox1
.MouseDown 3:
If
MouseButtons <> Windows.Forms.MouseButtons.Left
Then
Exit Sub
4: NewPoint.X = Me.Left - MousePosition.X 5: NewPoint.Y = Me.Top - MousePosition.Y 6:
End Sub
7:
Private Sub
PictureBox1_MouseMove(
ByVal
sender
As Object
,
ByVal
e
As
MouseEventArgs)
Handles
PictureBox1
.MouseMove 8:
If
MouseButtons <> Windows.Forms.MouseButtons.Left
Then Exit Sub
9: Me.Left = NewPoint.X + MousePosition.X 10: Me.Top = NewPoint.Y + MousePosition.Y 11:
End Sub
Pronto, desta forma estamos movendo um form1 a partir de uma picturebox!
0 comentários:
Postar um comentário