How to drag and move winform using mouse

删除回忆录丶 提交于 2019-12-06 03:46:52

EDIT: Changed to VB.NET - I really need to start reading the tags...

'Add these to your form class
Private MouseIsDown As Boolean = False
Private MouseIsDownLoc As Point = Nothing

'This is the MouseMove event of your panel
Private Sub panel_MouseMove(sender As Object, e As MouseEventArgs)
    If e.Button = MouseButtons.Left Then
        If MouseIsDown = False Then
            MouseIsDown = True
            MouseIsDownLoc = New Point(e.X, e.Y)
        End If

        Me.Location = New Point(Me.Location.X + e.X - MouseIsDownLoc.X, Me.Location.Y + e.Y - MouseIsDownLoc.Y)
    End If
End Sub

'And the MouseUp event of your panel
Private Sub panel_MouseUp(sender As Object, e As MouseEventArgs)
    MouseIsDown = False
End Sub
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!