3

我知道如果我不使用网络浏览器来填写我的表格,这会起作用。

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

但是,我找到了一个具有 Linux Alt+Drag 窗口功能的 Windows 程序,称为AltWindowDrag我知道我可以使用 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
4

1 回答 1

3

这是一个非常简单的技巧,当鼠标按下时,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
于 2012-07-22T18:55:27.017 回答