您的位置:首页 > 编程语言 > VB

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

2006-10-13 09:17 537 查看
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 Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer

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

Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal 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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: