我有一个没有边框的表单,我希望用户能够移动它。我一直无法找到任何可以让我这样做的东西。
是否可以移动边框设置为无的窗口?
最佳答案
引入一个 bool 变量,用于保存当前拖动表单时的状态,以及保存拖动起点的变量。然后 OnMove 相应地移动表单。由于这已经在其他地方得到了回答,我只是将其复制并粘贴到此处。
Class Form1
Private IsFormBeingDragged As Boolean = False
Private MouseDownX As Integer
Private MouseDownY As Integer
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseDown
If e.Button = MouseButtons.Left Then
IsFormBeingDragged = True
MouseDownX = e.X
MouseDownY = e.Y
End If
End Sub
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseUp
If e.Button = MouseButtons.Left Then
IsFormBeingDragged = False
End If
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseMove
If IsFormBeingDragged Then
Dim temp As Point = New Point()
temp.X = Me.Location.X + (e.X - MouseDownX)
temp.Y = Me.Location.Y + (e.Y - MouseDownY)
Me.Location = temp
temp = Nothing
End If
End Sub
End Class
从 http://www.dreamincode.net/forums/topic/59643-moving-form-with-formborderstyle-none/ 偷来的
关于vb.net - 允许用户移动无边框窗口,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17392088/