Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 移动没有标题栏的窗体_Vb.net_Mousemove - Fatal编程技术网

Vb.net 移动没有标题栏的窗体

Vb.net 移动没有标题栏的窗体,vb.net,mousemove,Vb.net,Mousemove,我一直在尝试移动一个没有标题栏的表格。我用的是标题栏应该在的面板。这是我最近一次这样做。一旦你看到我的代码,你可能会笑:) 现在,您不能使用画布移动它,但可以使用mousemove事件移动它。当我把它和表格一起移动时,它会下降到右边。谁能告诉我哪里出了问题。我猜这是因为MouseMove sub中的a和b变量没有值 Private Sub forml_MouseDown(sender As Object, e As MouseEventArgs) Handles Panel.MouseDown

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

现在,您不能使用画布移动它,但可以使用mousemove事件移动它。当我把它和表格一起移动时,它会下降到右边。谁能告诉我哪里出了问题。我猜这是因为MouseMove sub中的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

我非常感谢您的帮助。

我让它工作了!你明白了,汉斯。。我让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

代码选项非常简单。粘贴代码,选择它,然后按键盘上的Ctrl+K键或带有
{}
图像的工具栏按钮。请看它只是个bug。a和b变量必须是form类的成员,而不是局部变量。您的MouseMove事件处理程序将侦听窗体,而不是面板。谢谢,伙计。。。真的很抱歉…我尝试了链接中的一些其他代码,但它们对我不起作用。我正在使用VS2015。也许这有点关系。我知道这以前很容易。我确实把注意力集中在了面板上,所以现在我得到了那个部分。我只需要知道当我第一次移动表单时,是什么导致了这种侧推。