我知道如果我不使用Web浏览器填写表单,这将起作用。

Dim drag As Boolean
Dim mousex As Integer
Dim mousey As Integer

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
    MyBase.WndProc(m)
    '--- Alter the return value of WM_NCHITTEST when the ALT key is down
    If m.Msg = &H84 AndAlso (Control.ModifierKeys And Keys.Alt) <> 0 Then
        '--- Turn HTCLIENT into HTCAPTION
        If m.Result = 1 Then m.Result = 2
    End If
End Sub

Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
    If e.Button = Windows.Forms.MouseButtons.Left Then
        drag = True
        mousex = Windows.Forms.Cursor.Position.X - Me.Left
        mousey = Windows.Forms.Cursor.Position.Y - Me.Top
    End If

    Timer1.Enabled = True
    Timer1.Interval = 2500
End Sub

Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
    If drag Then
        Me.Top = Windows.Forms.Cursor.Position.Y - mousey
        Me.Left = Windows.Forms.Cursor.Position.X - mousex
    End If
End Sub

Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
    Timer1.Enabled = False
    drag = False
End Sub


但是我找到了一个用于Windows的程序,该程序具有名为AltWindowDrag的Linux Alt + Drag窗口功能,我知道我可以像下面那样使用Process.Start运行该程序...

Process.Start(Application.StartupPath & "\AltWindowDrag\AltWindowDrag.exe")


但是,与此有关的问题是当我关闭应用程序时,AltWindowDrag仍在运行。无论如何,我可以在窗体关闭时关闭AltWindowDrag吗?

任何帮助将不胜感激。

编辑!

另一个论坛上的一个家伙帮助我解决了这个问题,因此对于其他遇到相同问题的人也是如此。这是代码。

Dim proc As Process

Private Sub btnStart_Click(sender As System.Object, e As System.EventArgs) Handles btnStart.Click

    proc = Process.Start(Application.StartupPath & "\AltWindowDrag\AltWindowDrag.exe")
End Sub

Private Sub Form1_FormClosing(sender As System.Object, e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing

    If Not proc Is Nothing Then

        If Not proc.HasExited Then

            proc.Kill()
        End If
    End If
End Sub

最佳答案

这是一个非常简单的技巧,Windows会问您的应用程序,当鼠标下降时,单击了什么。您可以简单地撒谎并告诉它标题栏(而不是工作区)被单击。这使Windows在移动鼠标时自动移动窗口。将此代码粘贴到您的表单类中:

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
    MyBase.WndProc(m)
    '--- Alter the return value of WM_NCHITTEST when the ALT key is down
    If m.Msg = &H84 AndAlso (Control.ModifierKeys And Keys.Alt) <> 0 Then
        '--- Turn HTCLIENT into HTCAPTION
        If m.Result = 1 Then m.Result = 2
    End If
End Sub

10-04 15:06