public abstract void DrawPoint(PointStyle pointStyle, PointShape upperLeft, float radius);
private void Form1_Load(object sender, EventArgs e) { // Create winformCanvas WinformCanvas winformCanvas = new WinformCanvas(500, 500); //Draw point PointStyle pointStyle = new PointStyle(Color.Black); PointShape origin = new PointShape(250, 10); winformCanvas.DrawPoint(pointStyle, origin, 5); // Draw line Pen pen = new Pen(Color.Blue, 3); LineStyle lineStyle = new LineStyle(pen); LineShape line = new LineShape(new PointShape(50, 50), new PointShape(450, 50)); winformCanvas.DrawLine(lineStyle, line); // Draw polygon PointShape point1 = new PointShape(50, 80); PointShape point2 = new PointShape(100, 90); PointShape point3 = new PointShape(200, 100); PointShape point4 = new PointShape(250, 105); PointShape point5 = new PointShape(300, 100); PointShape point6 = new PointShape(350, 200); PointShape point7 = new PointShape(250, 210); List<PointShape> polygonPoints = new List<PointShape>(); polygonPoints.Add(point1); polygonPoints.Add(point2); polygonPoints.Add(point3); polygonPoints.Add(point4); polygonPoints.Add(point5); polygonPoints.Add(point6); polygonPoints.Add(point7); PolygonShape polygon = new PolygonShape(polygonPoints); Pen redPen = new Pen(Color.Red, 3); LineStyle polygonStyle = new LineStyle(redPen); winformCanvas.DrawPolygon(polygonStyle, polygon); //Draw lines polygonStyle.Pen.Color = Color.Yellow; for (int i = 0; i < polygonPoints.Count; i++) { polygonPoints[i].Y += 150; } winformCanvas.DrawLine(new LineStyle(redPen, false), new LineShape(polygonPoints)); // Draw String winformCanvas.DrawString("aaa", new Font(new FontFamily("宋体"), 10), lineStyle, point4); // Fill RegionStyle regionStyle = new RegionStyle(Color.Green, 2); polygon = new PolygonShape(new PointShape(250, 300), new PointShape(250, 400), new PointShape(300, 400), new PointShape(300, 300)); winformCanvas.FillPolygon(regionStyle, polygon); //Display on PictureBox picResult.Image = winformCanvas.Bitmap; winformCanvas.Save("test1.png"); }
/// <summary> /// /// </summary> /// <param name="pointStyle"></param> /// <param name="upperLeft"></param> /// <param name="radius"></param> public override void DrawPoint(PointStyle pointStyle, PointShape upperLeft, float radius) { graphics.FillEllipse(new SolidBrush(pointStyle.Color), new RectangleF(upperLeft, new SizeF(radius, radius))); }
private void btnDrawOnPdf_Click(object sender, EventArgs e) { // Create PdfCanvas PdfCanvas pdfCanvas = new PdfCanvas(); //Draw point PointStyle pointStyle = new PointStyle(Color.Black); PointShape origin = new PointShape(250, 10); pdfCanvas.DrawPoint(pointStyle, origin, 2); // Draw line Pen pen = new Pen(Color.Blue, 3); LineStyle lineStyle = new LineStyle(pen); LineShape line = new LineShape(new PointShape(50, 50), new PointShape(450, 50)); pdfCanvas.DrawLine(lineStyle, line); // Draw polygon PointShape point1 = new PointShape(50, 80); PointShape point2 = new PointShape(100, 90); PointShape point3 = new PointShape(200, 100); PointShape point4 = new PointShape(250, 105); PointShape point5 = new PointShape(300, 100); PointShape point6 = new PointShape(350, 200); PointShape point7 = new PointShape(250, 210); List<PointShape> polygonPoints = new List<PointShape>(); polygonPoints.Add(point1); polygonPoints.Add(point2); polygonPoints.Add(point3); polygonPoints.Add(point4); polygonPoints.Add(point5); polygonPoints.Add(point6); polygonPoints.Add(point7); PolygonShape polygon = new PolygonShape(polygonPoints); Pen redPen = new Pen(Color.Red, 3); LineStyle polygonStyle = new LineStyle(redPen); pdfCanvas.DrawPolygon(polygonStyle, polygon); //Draw lines polygonStyle.Pen.Color = Color.Yellow; for (int i = 0; i < polygonPoints.Count; i++) { polygonPoints[i].Y += 200; } pdfCanvas.DrawLine(new LineStyle(redPen, false), new LineShape(polygonPoints)); // Draw String pdfCanvas.DrawString("aaa", new Font(new FontFamily("宋体"), 10), lineStyle, new PointF(250, 220)); // Fill RegionStyle regionStyle = new RegionStyle(Color.Green, 2); polygon = new PolygonShape(new PointShape(250, 300), new PointShape(250, 400), new PointShape(300, 400), new PointShape(300, 300)); pdfCanvas.FillPolygon(regionStyle, polygon); // Add a page pdfCanvas.AddPage(); // Draw polygon on second page polygonStyle.Pen = new Pen(Color.Orange, 10); pdfCanvas.DrawPolygon(polygonStyle, polygon); //Save to a PDF file string fileName = "test1.pdf"; pdfCanvas.Save(fileName); Process.Start(fileName); }