3

フォームに入力する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

しかし、 AltWindowDragと呼ばれるLinux Alt + Dragウィンドウ機能を備えたWindows用のプログラムを見つけました。以下のように、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 に答える