简体   繁体   中英

move picture box vb.net mousekeydown and up

i am in visual basic dot net i have a picture box and i need to move it, the user click and move the mouse and the picturebox need move with it when the user release the mouse the picture box have location

Public Class Form1
Dim punto As New Point()

Private Sub PictureBox1_MouseDown1(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
punto = Cursor.Position
PictureBox1.Location = punto
End Sub

Private Sub PictureBox1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
punto = Cursor.Position
PictureBox1.Location = punto

End Sub
End Class 
Dim Offset As Point
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles PictureBox1.MouseDown
     Offset = New Point(-e.X, -e.Y)
End Sub

Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles PictureBox1.MouseMove
     If e.Button = Windows.Forms.MouseButtons.Left Then
         Dim Pos As Point = Me.PointToClient(MousePosition)
         Pos.Offset(Offset.X, Offset.Y)
         PictureBox1.Location = Pos
     End If
    End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM