2012-07-22 28 views
2

我知道這將工作如果我沒有使用網絡瀏覽器填寫我的表單。VB.NET合併Alt +窗口+拖入表格

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程序,具有Linux的使用Alt +拖放窗口功能稱爲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 
+0

如果是您使用的解決方案,則應將解決方案移至答案,並且可能接受答案。 – 2012-07-24 04:12:35

+0

兩天前我已經做到了。 – 2012-07-25 12:52:27

回答

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 
+0

我感覺真的很笨,一切看起來都很正確。也許我沒有進口東西,缺乏睡眠。 idk我做錯了什麼。 – 2012-07-22 19:42:04

+0

什麼都不需要導入。我無法猜出沒有錯誤信息的問題。 – 2012-07-22 19:43:24

+0

我沒有收到任何錯誤,只是不會通過alt +拖動拖動,或者點擊並拖動沒有標題欄。 – 2012-07-22 19:47:00