可拖动的无标题栏窗体,并且可以通过拉拽改变窗体大小。
注意:要设置form的controlbox属性为false,
特别注意: form.text要设置为空,否则不会把标题栏去掉
Dim MousX As Integer
Dim MousY As Integer
Dim CurrX As Integer
Dim CurrY As Integer
Public Sub myMouseDown(ByVal sender As Object, ByVal ex As MouseEventArgs) Handles MyBase.MouseDown
If ex.Button = MouseButtons.Left Then
'如果是鼠标左键,则不捕获鼠标
Me.Capture() = False
'获得鼠标坐标(相对于窗体)
MousX = ex.X
MousY = ex.Y
End If
End Sub
Public Sub myMouseMove(ByVal sender As Object, ByVal ex As MouseEventArgs) Handles MyBase.MouseMove
If ex.Button = MouseButtons.Left Then
'左键操作
CurrX = Me.Left - MousX + ex.X
CurrY = Me.Top - MousY + ex.Y
'设置窗体相对于屏幕的坐标
Me.SetDesktopLocation(CurrX, CurrY)
End If
End Sub
'
Public Sub myMouseUp(ByVal sender As Object, ByVal ex As MouseEventArgs) Handles MyBase.MouseUp
If ex.Button = MouseButtons.Left Then
Me.Capture() = True
End If
End Sub