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

C# 无边框窗体之窗体移动

2013-10-05 11:24 405 查看
点击窗体任意位置移动窗体:

需要添加命名空间:

using System.Runtime.InteropServices;


private const int WM_NCLBUTTONDOWN = 0x00A1;
private  const int HTCAPTION = 2;
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern bool ReleaseCapture();

protected override void OnMouseDown( MouseEventArgs e )
{
base.OnMouseDown( e );
if (e.Button == MouseButtons.Left)  // 按下的是鼠标左键
{
ReleaseCapture();   // 释放捕获
SendMessage(this.Handle, WM_NCLBUTTONDOWN, (IntPtr)HTCAPTION, IntPtr.Zero);    // 拖动窗体
}
}


View Code

原文地址:http://blog.sina.com.cn/s/blog_4982f49901013wlf.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: