移动没有标题栏的表单

时间:2015-09-02 17:25:30

标签: vb.net mousemove

我一直试图移动一个没有标题栏的表单。我正在使用标题栏所在的面板。这是我最接近这样做的。一旦你查看我的代码,你可能会笑:)

现在您无法使用画布移动它,但您可以使用mousemove事件移动它。当我用表格移动它时,它向下和向右下降。有人可以告诉我哪里出错了。我猜这是因为MouseMove子中的a和b变量没有任何价值。

Private Sub forml_MouseDown(sender As Object, e As MouseEventArgs) Handles Panel.MouseDown
    Dim newPoint As New System.Drawing.Point()
    Dim a As Integer
    Dim b As Integer

    a = Panel.MousePosition.X - Me.Location.X
    b = Panel.MousePosition.Y - Me.Location.Y
End Sub

Private Sub form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
    Dim newPoint As New System.Drawing.Point()

    Dim a As Integer
    Dim b As Integer

    If e.Button = MouseButtons.Left Then
        newPoint = Panel.MousePosition
        newPoint.X = newPoint.X - (a)
        newPoint.Y = newPoint.Y - (b)
        Me.Location = newPoint
    End If
End Sub

我真的很感激一些帮助。

1 个答案:

答案 0 :(得分:0)

我得到了它的工作!你得到了汉斯..我做了一个和一个班级的成员,我用你将在下面看到的代码处理了面板的事情。感谢你们所有的帮助。

:这可行

 Private Sub planel_MouseDown(sender As Object, e As MouseEventArgs) Handles Panel.MouseDown

        Dim newPoint As New System.Drawing.Point()

        a = Panel.MousePosition.X - Me.Location.X
        b = Panel.MousePosition.Y - Me.Location.Y

    End Sub
    Private Sub panel_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel.MouseMove

        Dim newPoint As New System.Drawing.Point()

        If e.Button = MouseButtons.Left Then

            newPoint = Panel.MousePosition
            newPoint.X = newPoint.X - (a)
            newPoint.Y = newPoint.Y - (b)
            Me.Location = newPoint
        End If
    End Sub