2012-07-22 30 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