源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

C# 无边框窗体之窗体移动实现代码

  • 时间:2020-09-11 08:48 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:C# 无边框窗体之窗体移动实现代码
点击窗体任意位置移动窗体: 需要添加命名空间: using System.Runtime.InteropServices;
[u]复制代码[/u] 代码如下:
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);    // 拖动窗体                  } }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部