移动图片框vb.net mousekeydown及以上

时间:2013-02-25 03:01:37

标签: .net vb.net picturebox keydown keyup

我在视觉基本点网我有一个图片框,我需要移动它,用户点击并移动鼠标,当用户释放鼠标图片框有位置时,图片框需要移动它

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 

1 个答案:

答案 0 :(得分:2)

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