注册 登录
编程论坛 VB.NET论坛

求救,点击图片picturebox移动窗体的问题。。。

goodwellxp 发布于 2008-01-24 23:22, 2513 次点击
请教高手,我在窗体里面放了个picturebox控件,想当鼠标点中控件不松手的时候,移动鼠标时,整个窗体随之移动。请问在picturebox里的mousedown里应该怎样写代码?
谢谢
3 回复
#2
fairy42008-01-25 08:36
Public X, Y As Integer
    Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
        X = e.X : Y = e.Y
    End Sub

    Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
        If X = e.X And Y = e.Y Then Exit Sub
        If e.Button = Windows.Forms.MouseButtons.Left Then
            Me.Left = Me.Left + e.X - X
            Me.Top = Me.Top + e.Y - Y
        End If
    End Sub
#3
goodwellxp2008-01-26 11:28
谢谢,我去试试
#4
goodwellxp2008-01-26 12:00
成功了,谢谢
1