当我单击并按住我的面板元素(它作为窗口顶部,因为我使用定制的 GUI)时,我试图让我的表单移动(就像你在其他应用程序上移动窗口一样)。
无论如何,我设法让它移动,但问题是,当我点击它时,表单会移动到我当前的光标位置,而不是像普通窗口那样移动(因为它会读取光标的位置并将表单的位置设置为该位置,因此移动它是不必要的)。
这是我的代码,我该怎么做才能让它正常工作?
Dim Moving As Boolean = False
Private Sub Panel1_MouseDown(sender As Object, e As MouseEventArgs) Handles Panel1.MouseDown
Moving = True
MouseMoveTimer.Start()
End Sub
Private Sub Panel1_MouseUp(sender As Object, e As MouseEventArgs) Handles Panel1.MouseUp
Moving = False
MouseMoveTimer.Stop()
End Sub
Private Sub MouseMoveTimer_Tick(sender As Object, e As EventArgs) Handles MouseMoveTimer.Tick
Me.Location = Cursor.Position
End Sub
新代码
Dim diff As Point = Cursor.Position - curpoint
Me.Location -= diff
curpoint = Cursor.Position