using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; using DevExpress.XtraPrinting; using DevExpress.XtraPrinting.BrickExporters; namespace CustomControls.Pattern { /// /// 图像绘制 /// public class PatternBrickExporter : PanelBrickExporter { private PatternBrick PatternBrick => Brick as PatternBrick; public override void Draw(IGraphics gr, RectangleF rect, RectangleF parentRect) { base.Draw(gr, rect, parentRect); /* 获取控件位置 */ var location = rect.Location; /* 记录文本控件和控件高度 */ var fontHeigh = PatternBrick.FontHeight; /* 根据花型坐标绘制连线 */ if (PatternBrick.LeftCodePointFs.Count > 1) { DrawConnectionLine(gr, fontHeigh, location, PatternBrick.LeftCodePointFs); } if (PatternBrick.MiddleCodePointFs.Count > 1) { DrawConnectionLine(gr, fontHeigh, location, PatternBrick.MiddleCodePointFs); } if (PatternBrick.SurplusCodePointFs.Count > 1) { DrawConnectionLine(gr, fontHeigh, location, PatternBrick.SurplusCodePointFs); } if (PatternBrick.RightCodePointFs.Count > 1) { DrawConnectionLine(gr, fontHeigh, location, PatternBrick.RightCodePointFs); } /* 绘制各个花型间隔线 */ var controlWidth = PatternBrick.FontHeight; var lowestY = PatternBrick.CountFs.Y; DrawVerticalLine(gr, new PointF(location.X + 20f, location.Y), new PointF(location.X + 20f, location.Y + lowestY)); List pointFs = new List(); if (PatternBrick.LeftCodePointFs.Count > 0) { var fs = PatternBrick.LeftCodePointFs; pointFs.Add(fs[fs.Count - 1]); } if (PatternBrick.MiddleCodePointFs.Count > 0) { var fs = PatternBrick.MiddleCodePointFs; pointFs.Add(fs[0]); pointFs.Add(fs[fs.Count - 1]); /* 绘制循环线 */ var firstX = location.X + fs[0].X; var firstY = location.Y + lowestY - controlWidth; var lastX = location.X + fs[fs.Count - 1].X + controlWidth * 2f; var lastY = location.Y + lowestY - controlWidth; var firstPointF = new PointF(firstX, firstY); var lastPointF = new PointF(lastX, lastY); DrawVerticalLine(gr, firstPointF, lastPointF); /* 绘制箭头 */ var leftArrowX = firstX + 15f; var leftArrowY = firstY + 10f; var rightArrowX = lastX - 15f; var rightArrowY = lastY - 10f; var leftPointF = new PointF(leftArrowX, leftArrowY); var rifhtPointF = new PointF(rightArrowX, rightArrowY); DrawVerticalLine(gr, firstPointF, leftPointF); DrawVerticalLine(gr, lastPointF, rifhtPointF); } if (PatternBrick.SurplusCodePointFs.Count > 0) { var fs = PatternBrick.SurplusCodePointFs; pointFs.Add(fs[0]); pointFs.Add(fs[fs.Count - 1]); } if (PatternBrick.RightCodePointFs.Count > 0) { var fs = PatternBrick.RightCodePointFs; pointFs.Add(fs[0]); pointFs.Add(fs[fs.Count - 1]); } for (int i = 0; i < pointFs.Count; i += 2) { float lineX; if (i + 1 < pointFs.Count - 1) { lineX = location.X + pointFs[i].X + controlWidth + (pointFs[i + 1].X - pointFs[i].X) / 2; } else { lineX = location.X + pointFs[i].X + controlWidth * 2f; } PointF pt1 = new PointF(lineX, location.Y); PointF pt2 = new PointF(lineX, lowestY); DrawVerticalLine(gr, pt1, pt2); } } /// /// 绘制连接线 /// private void DrawConnectionLine(IGraphics gr, float fontHeigh, PointF location, List codePointFs) { /* 循环绘制连线 */ for (var i = 0; i < codePointFs.Count - 1; i++) { /* 设置笔刷 */ var pen = BrickPaint.GetPen(Color.Black, GraphicsUnitConverter.DipToDoc(1f)); /* 根据两个控件的位置高低设置起始位置 */ var location1 = codePointFs[i]; var location2 = codePointFs[i + 1]; var pt1 = new PointF(); var pt2 = new PointF(); if (location1.Y < location2.Y) { pt1 = new PointF(location1.X + fontHeigh + location.X, location1.Y + fontHeigh + location.Y); pt2 = new PointF(location2.X + fontHeigh + location.X, location2.Y + location.Y); } else { pt1 = new PointF(location1.X + fontHeigh + location.X, location1.Y + location.Y); pt2 = new PointF(location2.X + fontHeigh + location.X, location2.Y + fontHeigh + location.Y); } /* 设置连线平滑 */ gr.SmoothingMode = SmoothingMode.AntiAlias; gr.DrawLine(pen, pt1, pt2); } } /// /// 绘制纵向间隔线 /// private void DrawVerticalLine(IGraphics gr, PointF pt1, PointF pt2) { /* 设置笔刷 */ var pen = BrickPaint.GetPen(Color.Black, GraphicsUnitConverter.DipToDoc(1f)); /* 设置连线平滑 */ gr.SmoothingMode = SmoothingMode.AntiAlias; gr.DrawLine(pen, pt1, pt2); } } }