鼠标移动没有标题栏的winform窗口

来源:互联网 发布:中国地质图书馆网络 编辑:程序博客网 时间:2024/05/01 23:57

昨天在做项目的时候想实现一下这个功能.也是在网上找了几种方法.挑了个比较简单的(我比较懒) ,效果还行,只是用了这个鼠标的其他事件都不管用了. 不知道要怎么解决这个问题

  private const int WM_NCHITTEST = 0x84;
  private const int HTCLIENT = 0x1;
  private const int HTCAPTION = 0x2;

  protected override void WndProc(ref Message m)
  {
   const int WM_NCHITTEST = 0x84;
   const int HTCLIENT = 0x01;
   const int HTCAPTION = 0x02;

   if (m.Msg == WM_NCHITTEST)
   {
    this.DefWndProc(ref m);
    if (m.Result.ToInt32() == HTCLIENT)
     m.Result = new IntPtr(HTCAPTION);
    else
     base.WndProc(ref m);
   }
   else
    base.WndProc(ref m);
  }

原创粉丝点击