Public Class Form1
Inherits System.Windows.Forms.Form
Private mouse_offset As Point
Private Sub form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
mouse_offset = New Point(e.X, e.Y)
End Sub
Private Sub form1_MouseMove(ByVal Sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
’按住鼠标左右键均可拖动窗体
If e.Button = MouseButtons.Left Or e.Button = MouseButtons.Right Then
Dim mousePos As Point = Sender.findform().MousePosition 这段虽知道定义了一个点,但后面的代码不清楚
’获得鼠标偏移量
mousePos.Offset(-mouse_offset.X, -mouse_offset.Y)' ‘这个鼠标的偏移量是怎么会事啊?而切前面还有个负号,不懂啊
’设置窗体随鼠标一起移动
Sender.findform().Location = mousePos'这段望高手也解释一下嘛
End If
End Sub
Private Sub BtnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
’关闭窗体
Me.Close()
End Sub
End Class