欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C#实现Winform无边框移动的方法

程序员文章站 2022-06-30 10:28:33
本文实例讲述了c#实现winform无边框移动的方法。分享给大家供大家参考。具体如下: const int htleft = 10; const int htr...

本文实例讲述了c#实现winform无边框移动的方法。分享给大家供大家参考。具体如下:

const int htleft = 10;
const int htright = 11;
const int httop = 12;
const int httopleft = 13;
const int httopright = 14;
const int htbottom = 15;
const int htbottomleft = 0x10;
const int htbottomright = 17;
protected override void wndproc(ref message m)
{
 switch (m.msg)
 {
  case 0x0084:
   base.wndproc(ref m);
   point vpoint = new point((int)m.lparam & 0xffff,
    (int)m.lparam >> 16 & 0xffff);
   vpoint = pointtoclient(vpoint);
   if (vpoint.x <= 5)
    if (vpoint.y <= 5)
     m.result = (intptr)httopleft;
    else if (vpoint.y >= clientsize.height - 5)
     m.result = (intptr)htbottomleft;
    else m.result = (intptr)htleft;
   else if (vpoint.x >= clientsize.width - 5)
    if (vpoint.y <= 5)
     m.result = (intptr)httopright;
    else if (vpoint.y >= clientsize.height - 5)
     m.result = (intptr)htbottomright;
    else m.result = (intptr)htright;
   else if (vpoint.y <= 5)
    m.result = (intptr)httop;
   else if (vpoint.y >= clientsize.height - 5)
    m.result = (intptr)htbottom;
   break;
  case 0x0201://鼠标左键按下的消息 
   m.msg = 0x00a1;//更改消息为非客户区按下鼠标 
   m.lparam = intptr.zero;//默认值 
   m.wparam = new intptr(2);//鼠标放在标题栏内 
   base.wndproc(ref m);
   break;
  default:
   base.wndproc(ref m);
   break;
 }
}

希望本文所述对大家的c#程序设计有所帮助。