第12章-C#高级编程网络应用开发综合实例习题解答

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

第12章网络应用开发综合实例1习题12参考解答1.多机联合绘图系统中为何不使用Panel作为画板?【解答】如果使用Panel作为画板,在绘制图形图像时会出现闪烁现象。因此单独设计一个用户控件用作画板,通过设置该用户控件的【DoubleBuffered】属性值为true来启用双缓冲,从而避免出现闪烁现象。2.读懂多机联合绘图系统的源程序,在此基础上进行功能扩展。1)实现任意大小三角形和六边形的绘制。2)实现任意形状的带箭头曲线、封闭曲线的绘制。【解答】1)在项目中添加一个新类DrawPloygon使其从TrackRectangle继承,重写TrackRectangle类中Draw方法实现椭圆的绘制。classDrawPloygon:TrackRectangle{publicRectangleobjRectangle;//绘制的多边形外接矩形publicDrawPloygon(){}publicDrawPloygon(intx,inty,intwidth,intheight,ColorpenColor,intid){this.objRectangle=newRectangle(x,y,width,height);this.penColor=penColor;this.ID=id;}publicoverridevoidDraw(Graphicsg)//重写基类的方法{using(Penpen=newPen(this.penColor)){intx=this.objRectangle.X;inty=this.objRectangle.Y;//三角形的三个顶点Point[]points=newPoint[3];points[0]=newPoint((2*x+this.objRectangle.Width)/2,y);points[1]=newPoint(x,y+this.objRectangle.Height);points[2]=newPoint(x+this.objRectangle.Width,y+this.objRectangle.Height);g.DrawPolygon(pen,points);}}}第12章网络应用开发综合实例2若要实现六边形的绘制,只需要修改Draw方法即可。具体代码如下:publicoverridevoidDraw(Graphicsg){using(Penpen=newPen(this.penColor)){intx=this.objRectangle.X;inty=this.objRectangle.Y;//其余六个顶点Point[]points=newPoint[6];points[0]=newPoint((2*x+this.objRectangle.Width)/4,y);points[1]=newPoint(x,(2*y+this.objRectangle.Height)/2);points[2]=newPoint((2*x+this.objRectangle.Width)/4,y+this.objRectangle.Height);points[3]=newPoint((2*x+this.objRectangle.Width)*3/4,y+this.objRectangle.Height);points[4]=newPoint(x+this.objRectangle.Width,(2*y+this.objRectangle.Height)/2);points[5]=newPoint((2*x+this.objRectangle.Width)*3/4,y);g.DrawPolygon(pen,points);}}2)实现任意形状的带箭头的曲线、封闭曲线的绘制。从TrackCurve类派生子类DrawArrowCurve、DrawClosedCurve类,分别重写Draw方法。对于带箭头的曲线DrawArrowCurve类的Draw方法的定义如下:publicoverridevoidDraw(Graphicsg){Point[]pts=newPoint[pointList.Count];pointList.CopyTo(pts);Penpen=newPen(penColor,penWidth);g.SmoothingMode=SmoothingMode.AntiAlias;AdjustableArrowCapmyArrow=newAdjustableArrowCap(4,4,true);pen.CustomEndCap=myArrow;if(pts.Length3){if(pts.Length1){g.DrawLine(pen,pts[0],pts[1]);}}else{第12章网络应用开发综合实例3g.DrawCurve(pen,pts);}pen.Dispose();}对于绘制封闭的曲线来说,设计类DrawClosedCurve其中Draw方法定义如下:publicoverridevoidDraw(Graphicsg){Point[]pts=newPoint[pointList.Count];pointList.CopyTo(pts);Penpen=newPen(penColor,penWidth);g.SmoothingMode=SmoothingMode.AntiAlias;AdjustableArrowCapmyArrow=newAdjustableArrowCap(4,4,true);pen.CustomEndCap=myArrow;if(pts.Length3){if(pts.Length1){g.DrawLine(pen,pts[0],pts[1]);}}else{g.DrawClosedCurve(pen,pts);}pen.Dispose();}

1 / 3
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功