📅  最后修改于: 2023-12-03 15:35:34.149000             🧑  作者: Mango
在 VB.NET 中,通过设置 Form 的 BorderStyle 为 None 可以实现无标题栏的窗口,但此时鼠标无法拖动窗口。本文将介绍如何在无标题栏窗口中实现鼠标拖动窗口效果。
Me.FormBorderStyle = FormBorderStyle.None
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
'记录鼠标按下时的坐标
Me.mouseOffset = New Point(-e.X, -e.Y)
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
'鼠标左键按下并且移动窗口
If e.Button = Windows.Forms.MouseButtons.Left Then
Dim mousePos As Point = Control.MousePosition
mousePos.Offset(Me.mouseOffset.X, Me.mouseOffset.Y)
Me.Location = mousePos
End If
End Sub
Private mouseOffset As Point
Public Class Form1
Private mouseOffset As Point
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
'记录鼠标按下时的坐标
Me.mouseOffset = New Point(-e.X, -e.Y)
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
'鼠标左键按下并且移动窗口
If e.Button = Windows.Forms.MouseButtons.Left Then
Dim mousePos As Point = Control.MousePosition
mousePos.Offset(Me.mouseOffset.X, Me.mouseOffset.Y)
Me.Location = mousePos
End If
End Sub
End Class
以上就是在 VB.NET 中实现无标题栏拖动窗口的方法,希望对您有所帮助。