C#实现Winform无边框移动的方法
本文实例讲述了C#实现Winform无边框移动的方法。分享给大家供大家参考。具体如下:
constintHTLEFT=10; constintHTRIGHT=11; constintHTTOP=12; constintHTTOPLEFT=13; constintHTTOPRIGHT=14; constintHTBOTTOM=15; constintHTBOTTOMLEFT=0x10; constintHTBOTTOMRIGHT=17; protectedoverridevoidWndProc(refMessagem) { switch(m.Msg) { case0x0084: base.WndProc(refm); PointvPoint=newPoint((int)m.LParam&0xFFFF, (int)m.LParam>>16&0xFFFF); vPoint=PointToClient(vPoint); if(vPoint.X<=5) if(vPoint.Y<=5) m.Result=(IntPtr)HTTOPLEFT; elseif(vPoint.Y>=ClientSize.Height-5) m.Result=(IntPtr)HTBOTTOMLEFT; elsem.Result=(IntPtr)HTLEFT; elseif(vPoint.X>=ClientSize.Width-5) if(vPoint.Y<=5) m.Result=(IntPtr)HTTOPRIGHT; elseif(vPoint.Y>=ClientSize.Height-5) m.Result=(IntPtr)HTBOTTOMRIGHT; elsem.Result=(IntPtr)HTRIGHT; elseif(vPoint.Y<=5) m.Result=(IntPtr)HTTOP; elseif(vPoint.Y>=ClientSize.Height-5) m.Result=(IntPtr)HTBOTTOM; break; case0x0201://鼠标左键按下的消息 m.Msg=0x00A1;//更改消息为非客户区按下鼠标 m.LParam=IntPtr.Zero;//默认值 m.WParam=newIntPtr(2);//鼠标放在标题栏内 base.WndProc(refm); break; default: base.WndProc(refm); break; } }
希望本文所述对大家的C#程序设计有所帮助。