胖在一方

出得厅堂入得厨房的胖子

导航

拖动无标题的窗体(vb.net & c#)

Posted on 2006-10-13 09:17  胖在一方  阅读(551)  评论(0)    收藏  举报
c#
using System.Runtime.InteropServices;

[DllImport(
"user32.dll"
)]
public static extern int
 ReleaseCapture();
[DllImport(
"user32.dll"
)]
public static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int
 lParam);
public const int WM_SYSCOMMAND = 0x0112
;
public const int SC_MOVE = 0xF010
;
public const int HTCAPTION = 0x0002
;
     
private void Form1_MouseDown(object
 sender, System.Windows.Forms.MouseEventArgs e)
{
       ReleaseCapture();
       SendMessage(
this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0
);
}

vb.net
  Public Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As IntegerByVal wMsg As IntegerByVal wParam As IntegerByVal lParam As IntegerAs Integer

    
Public Declare Function ReleaseCapture Lib "user32.dll" Alias "ReleaseCapture" () As Integer



 
Private Sub PictureBox1_MouseDown(ByVal sender As ObjectByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
        
If e.Button = MouseButtons.Left Then

            
'    为当前的应用程序释放鼠标捕获 
            ReleaseCapture()
            
'       发送消息,让系统误以为你在标题拦上按下鼠标 

            SendMessage(Me.Handle.ToInt32, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0)
        
End If

    
End Sub