public static void DrawPipes(this Graphics g, float width, SegmentList poly, Color mid_color, Color edge_color) { for (int i = 0; i < poly.Lines.Count; i++) { using (GraphicsPath gp = new GraphicsPath()) { var start = poly.Lines[i].StartPoint; gp.AddEllipse(start.Center.X - width / 2, start.Center.Y - width / 2, width, width); if (i == poly.Lines.Count - 1) { var end = poly.Lines[i].EndPoint; gp.AddEllipse(end.Center.X - width / 2, end.Center.Y - width / 2, width, width); } using (PathGradientBrush brush = new PathGradientBrush(gp)) { brush.CenterColor = mid_color; brush.SurroundColors = new Color[] { edge_color }; brush.CenterPoint = start.Center; g.FillPath(brush, gp); } } if (i > 0) { DrawPipe(g, width, poly.Lines[i], mid_color, edge_color); } } }
public PolyLineForm() { this.DoubleBuffered = true; InitializeComponent(); DrawScale = new SizeF(1, -1); DrawOrigin = new PointF(pictureBox1.Width / 2, pictureBox1.Height / 2); Selected = -1; Poly = new SegmentList(true, new PointF(-90, -90), new PointF(0, -30), new PointF(90, -90), new PointF(60, 60), new PointF(0, 30), new PointF(-60, 60)); this.pictureBox1.Paint += new PaintEventHandler(pictureBox1_Paint); this.pictureBox1.Resize += new EventHandler(pictureBox1_Resize); this.pictureBox1.MouseDown += new MouseEventHandler(pictureBox1_MouseDown); this.pictureBox1.MouseUp += new MouseEventHandler(pictureBox1_MouseUp); this.pictureBox1.MouseMove += new MouseEventHandler(pictureBox1_MouseMove); }
private void pictureBox1_Paint(object sender, PaintEventArgs e) { e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; e.Graphics.TranslateTransform(DrawOrigin.X, DrawOrigin.Y); e.Graphics.ScaleTransform(DrawScale.Width, DrawScale.Height); SegmentList L1 = Poly.Offset(7); SegmentList L2 = Poly.Offset(-7); for (int i = 0; i < Count; i++) { using (Pen pen = new Pen(Color.Black, 1)) { pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid; e.Graphics.DrawPoint(Poly.Lines[i].StartPoint, pen); e.Graphics.DrawPoint(Poly.Lines[i].EndPoint, pen); pen.Width = 2; e.Graphics.DrawLine(L1.Lines[i], pen); e.Graphics.DrawLine(L2.Lines[i], pen); pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; pen.Width = 1; //e.Graphics.DrawPipe(12f, Poly.Lines[i], Color.Yellow, Color.Black); //e.Graphics.DrawLine(Poly.Lines[i], pen); } if (i == Selected) { using (Pen pen = new Pen(Color.FromArgb(92, 250, 92, 92), 2)) { pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid; e.Graphics.DrawLine(L1.Lines[i].Offset(2), pen); e.Graphics.DrawLine(L2.Lines[i].Offset(-2), pen); //e.Graphics.DrawLine(Poly.Lines[i], pen); } } } }