【问题标题】:Moving a form without a titlebar移动没有标题栏的表单
【发布时间】:2015-09-02 17:25:29
【问题描述】:

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

现在你不能用画布移动它,但是你可以用 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

非常感谢您的帮助。

【问题讨论】:

  • 代码选项非常简单。粘贴代码,选择它,然后按键盘上的 Ctrl+K 或带有 {} 图像的工具栏按钮。
  • 这只是越野车。您的 a 和 b 变量必须是表单类的成员,而不是局部变量。您的 MouseMove 事件处理程序侦听表单,而不是面板。
  • 谢谢大佬...真的很感激...
  • 我尝试了链接中的一些其他代码,但它们对我不起作用。我正在使用VS2015。也许这与它有一点关系。我知道它曾经很容易。我确实让它专注于面板,所以现在我得到了那部分。当我第一次移动表单时,只需要知道是什么导致了侧身。

标签: vb.net mousemove


【解决方案1】:

我让它工作了!你明白了,汉斯。我创建了班级的 a 和 b 成员,并通过您将在下面看到的代码处理了面板问题。感谢你们两位的帮助。

:这行得通

 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

【讨论】:

    猜你喜欢
    • 2014-07-20
    • 2011-07-27
    • 2018-07-10
    • 1970-01-01
    • 2015-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-30
    相关资源
    最近更新 更多