问题描述
C#中formborderstyle为none的窗口怎样实现缩放,用鼠标任意的改变它大小?还有,这种类型的窗口做主窗口时,点击任务栏中标签的时候无法实现最小化,怎么解决?要用到窗口和任务栏的句柄么?
解决方案
解决方案二:
privateconstintWM_NCHITTEST=0x84;privateconstintHTCLIENT=0x1;privateconstintHTCAPTION=0x2;protectedoverridevoidWndProc(refMessagem){base.WndProc(refm);if(m.Msg==WM_NCHITTEST&&this.FormBorderStyle==FormBorderStyle.None){Pointz=Control.MousePosition;if(z!=null){Pointtmp=this.PointToScreen(newPoint());z.X-=tmp.X;z.Y-=tmp.Y;}PaddingresizePadding=newPadding(3);intresult=0;if(z.X<(Left+resizePadding.Left))result=10;elseif(z.X>(Right-resizePadding.Right))result=11;if(z.Y<(Top+resizePadding.Top)){switch(result){case0:result=12;break;case10:result=13;break;case11:result=14;break;default:break;}}elseif(z.Y<(Top+20)){switch(result){case0:result=2;break;default:break;}}elseif(z.Y>(Bottom-resizePadding.Bottom)){switch(result){case0:result=15;break;case10:result=16;break;case11:result=17;break;default:break;}}if(result!=0)m.Result=(IntPtr)result;}}
解决方案三:
加上移动部分:protectedoverridevoidWndProc(refMessagem){base.WndProc(refm);#regionMovewithoutFormBorderif(m.Msg==WM_NCHITTEST){this.DefWndProc(refm);if(m.Result.ToInt32()==HTCLIENT)m.Result=newIntPtr(HTCAPTION);}#endregion#regionResizewithoutFormBorderif(m.Msg==WM_NCHITTEST&&this.FormBorderStyle==FormBorderStyle.None){Pointz=Control.MousePosition;if(z!=null){Pointtmp=this.PointToScreen(newPoint());z.X-=tmp.X;z.Y-=tmp.Y;}PaddingresizePadding=newPadding(3);intresult=0;if(z.X<(Left+resizePadding.Left))result=10;elseif(z.X>(Right-resizePadding.Right))result=11;if(z.Y<(Top+resizePadding.Top)){switch(result){case0:result=12;break;case10:result=13;break;case11:result=14;break;default:break;}}elseif(z.Y<(Top+20)){switch(result){case0:result=2;break;default:break;}}elseif(z.Y>(Bottom-resizePadding.Bottom)){switch(result){case0:result=15;break;case10:result=16;break;case11:result=17;break;default:break;}}if(result!=0)m.Result=(IntPtr)result;}#endregion}
解决方案四:
谢谢!但点击任务栏中标签的时候无法实现最小化的问题还是没能解决。当前窗口如何知道鼠标在点击任务栏标签?