2 color link with arrowhead in middle


#1

Have any one success on link with 2 color style and arrowhead at the middle ? like picture below:


#2

I can’t see the picture that you reference, but the FAQ does talk about drawing arrowheads in the middle of links. Look for the topic: “How can I have the arrowhead drawn at the middle of the link?”


#3
I couldn't tell exactly what you wanted, even after you sent me the picture, so here's my guess. Sorry for the formatting, which got lost when pasting into this "Post Reply" window, and I'm not going to bother to fix when VS.NET will do it for you. [Serializable] public class TwoColorLink : GoLink { public TwoColorLink() { this.Orthogonal = true; Pen pen = new Pen(Color.Blue); pen.DashPattern = myDashPattern; this.Pen = pen; this.Brush = Brushes.White; this.ToArrow = true; this.ToArrowFilled = true; this.ToArrowLength = 10; this.ToArrowShaftLength = 10; this.ToArrowWidth = 10; } public override void Paint(Graphics g, GoView view) { if (this.Style == GoStrokeStyle.Line) { int num = this.PointsCount; if (num < 2) return; int half = (num-1)/2; for (int i = 0; i < num-1; i++) { PointF a = GetPoint(i); PointF b = GetPoint(i+1); Pen pen = this.Pen; if (pen != null) { if (i < half) { g.DrawLine(pen, a, b); } else if (i == half) { PointF m = new PointF((a.X+b.X)/2, (a.Y+b.Y)/2); g.DrawLine(pen, a, m); if (mySecondPen == null) { mySecondPen = new Pen(this.SecondColor); mySecondPen.DashPattern = myDashPattern; } g.DrawLine(mySecondPen, m, b); if (this.ToArrow) { PointF a2, m2; CalculateArrowPoints(i, i+1, out a2, out m2); CalculateArrowhead(a2, m2, true, myPoly); DrawArrowhead(g, view, Pens.Black, this.Brush, true, 0, 0, myPoly); } } else { g.DrawLine(mySecondPen, a, b); } } } } else { base.Paint(g, view); } } private void CalculateArrowPoints(int i, int j, out PointF a2, out PointF m2) { PointF a = GetPoint(i); PointF b = GetPoint(j); a2 = a; m2 = b; float len = (float)Math.Sqrt((a.X-b.X)*(a.X-b.X) + (a.Y-b.Y)*(a.Y-b.Y)); float alen = this.ToArrowLength; if (len > alen) { a2 = a; float frac = alen/(len*2) + 0.5f; m2 = new PointF(((1-frac)*a.X+frac*b.X), ((1-frac)*a.Y+frac*b.Y)); } else if (len < alen/2) { if (i >= 1 && j <= this.PointsCount-2) CalculateArrowPoints(i-1, j+1, out a2, out m2); } } public override Pen Pen { set { base.Pen = value; mySecondPen = null; } } public Color SecondColor { get { return mySecondColor; } set { Color old = mySecondColor; if (old != value) { mySecondColor = value; Changed(ChangedSecondColor, 0, old, NullRect, 0, value, NullRect); mySecondPen = null; } } } public const int ChangedSecondColor = GoObject.LastChangedHint + 33; private static Random myRandom = new Random(); private static float[] myDashPattern = new float[2] { 4, 4 }; private static PointF[] myPoly = new PointF[4]; // only used by Paint private Color mySecondColor = Color.Red; [NonSerialized] private Pen mySecondPen = null; }