问题描述
我是参考这里http://www.microsoft.com/china/community/Column/60.mspx我做的也是一个无边框的窗体现在已经实现了向右拉伸功能。方法(获得当前的鼠标横坐标(mousemove)FORM.WITCH=鼠标横坐标-location.X)如何实现向左拉伸?我思考的方法(FORM.WITCH=this.Right-当前鼠标横坐标,但是表现出来时窗体左边框没动右边框在增加缩小)不知道我是不是写错了。或者要实现无边框窗体的伸缩大小有没有另外的好方法?主要是不知道怎么样的状态下重绘?大家给点思路。
解决方案
解决方案二:
//向右if(e.X>=wid-5&&e.Y<=hig-5&&e.Y>=5){mouse=newMouseSizeRight(Location.X);return;}//向右下if((e.X>=wid-5&&e.Y>=hig-5)||(e.Y>=hig-5&&e.X>=wid-5)){mouse=newMouseSizeBottomRight(Location.X,Location.Y);return;}//向下if(y>=hig-5&&x<=wid-5&&x>=5){mouse=newMouseSizeBottom(Location.Y);return;}//向左下if(x<=5&&y>=hig-5&&y<=hig){mouse=newMouseSizeBottomLeft(Location.Y,wid,hig);return;}//向左拉if(e.X<=5&&e.Y<=hig-5&&e.Y>=5){mouse=newMouseSizeLeft(hig);return;}//向左上拉if(e.X<=5&&e.Y<=5&&e.Y>0){mouse=newMouseSizeTopLeft(Location.Y,hig);return;}//向上拉if(e.Y<=5&&e.X<=wid-5&&e.X>=5){mouse=newMouseSizeTop(Location.X,Location.Y,wid,hig);return;}//向右上if(e.X>=wid-5&&e.Y<=5){mouse=newMouseSizeTopRight(Location.X,Location.Y,wid,hig);return;}//拉右边publicclassMouseSizeRight:MouseAction{privateintlx;publicMouseSizeRight(intLocationX){lx=LocationX;}publicoverridevoidAction(intScreenX,intScreenY,System.Windows.Forms.Formform){form.Width=ScreenX-lx;form.Invalidate();}}//向下拉publicclassMouseSizeBottom:MouseAction{privateintly;publicMouseSizeBottom(intLocationY){ly=LocationY;}publicoverridevoidAction(intScreenX,intScreenY,System.Windows.Forms.Formform){form.Height=ScreenY-ly;form.Invalidate();}}//向左下拉publicclassMouseSizeBottomLeft:MouseAction{privateintwid;privateinthig;privateintly;publicMouseSizeBottomLeft(intLocationY,intLocationWid,intLocationHig){ly=LocationY;wid=LocationWid;hig=LocationHig;}publicoverridevoidAction(intScreenX,intScreenY,System.Windows.Forms.Formform){inta=ScreenX;intb=form.DesktopLocation.Y;form.SetDesktopBounds(a,b,form.Right-a,ScreenY-ly);form.Invalidate();form.Invalidate();}}//拉右下角publicclassMouseSizeBottomRight:MouseAction{privateintlx;privateintly;publicMouseSizeBottomRight(intLocationX,intLocationY){lx=LocationX;ly=LocationY;}publicoverridevoidAction(intScreenX,intScreenY,System.Windows.Forms.Formform){form.Width=ScreenX-lx;form.Height=ScreenY-ly;form.Invalidate();}}//拉左边publicclassMouseSizeLeft:MouseAction{privateinthig;publicMouseSizeLeft(intLocationhig){hig=Locationhig;}publicoverridevoidAction(intScreenX,intScreenY,System.Windows.Forms.Formform){intb=form.DesktopLocation.Y;form.SetDesktopBounds(ScreenX,b,form.Right-ScreenX,hig);form.Invalidate();}}//拉左上publicclassMouseSizeTopLeft:MouseAction{privateinthig;privateintly;publicMouseSizeTopLeft(intLxcationY,intLxcationHig){ly=LxcationY;hig=LxcationHig;}publicoverridevoidAction(intScreenX,intScreenY,System.Windows.Forms.Formform){form.SetDesktopBounds(ScreenX,ScreenY,form.Right-ScreenX,hig-ScreenY+ly);form.Invalidate();}}//拉上边publicclassMouseSizeTop:MouseAction{privateinthig;privateintwid;privateintlx;privateintly;publicMouseSizeTop(intLxcationX,intLxcationY,intLxcationWid,intLxcationHig){hig=LxcationHig;lx=LxcationX;wid=LxcationWid;ly=LxcationY;}publicoverridevoidAction(intScreenX,intScreenY,System.Windows.Forms.Formform){form.SetDesktopBounds(lx,ScreenY,wid,hig-ScreenY+ly);form.Invalidate();}}//拉右上publicclassMouseSizeTopRight:MouseAction{privateinthig;privateintwid;privateintlx;privateintly;publicMouseSizeTopRight(intLxcationX,intLxcationY,intLxcationWid,intLxcationHig){hig=LxcationHig;lx=LxcationX;wid=LxcationWid;ly=LxcationY;}publicoverridevoidAction(intScreenX,intScreenY,System.Windows.Forms.Formform){form.SetDesktopBounds(lx,ScreenY,ScreenX-lx,hig-ScreenY+ly);form.Invalidate();}