最近做了一个类似形地图标注的一个小项目,总结一下图形化编程的一点心得。
首先来看看几个重要的画图对象:
System.Drawing.Graphics //画布 System.Drawing.Drawing2D.GraphicsPath //画图路径,也就是在图上显示的线 System.Drawing.Drawing2D.Matrix //图像缩放对象
我们再来看看几个重要方法:
//g为Graphics对象 path为GraphicsPath对象 path.AddLine(Point1, Point2); //在两点间添加一条直线 path.AddArc(x,y,width,height,startAngle,sweepAngle); //添加弧线 path.AddPie(x,y,width,height,startAngle,sweepAngle); //添加扇形 g.DrawPath(new Pen(Color.Gray, 1), path); //将路径画到画布 g.FillEllipse(brush,x,y,width,height); //在画布上画一个椭圆 g.DrawLine(pen,point1,point2); //在画布上画一条直线 path.Transform(matrix); //将图像按比例缩放 g.TranslateTransform(x, y, MatrixOrder.Prepend); //平移画布