C# 无边框窗体之窗体移动实现代码_C#教程-查字典教程网
C# 无边框窗体之窗体移动实现代码
C# 无边框窗体之窗体移动实现代码
发布时间:2016-12-28 来源:查字典编辑
摘要:点击窗体任意位置移动窗体:需要添加命名空间:usingSystem.Runtime.InteropServices;复制代码代码如下:pri...

点击窗体任意位置移动窗体:

需要添加命名空间:

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); // 拖动窗体

}

}

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新C#教程学习
    热门C#教程学习
    编程开发子分类