public void Draw(Graphics g, Point location, Size mapSize) { var imageTip = Tip.Scale(mapSize).Translate(location).ToPoint(); var imageEnd = End.Scale(mapSize).Translate(location).ToPoint(); // shorten the arrow on one side so it doesn't overlap with the planet if (IsArrow && !IsColonyLink) { Shorten(imageEnd, ref imageTip); } using (var brush = new LinearGradientBrush(imageTip, imageEnd, TipColor, EndColor)) //using (var brush = new SolidBrush(Color.Red)) using (var pen = new Pen(brush, LineWidth*mapSize.Width)) { CustomLineCap cap; if (IsArrow) { if (IsColonyLink) { pen.CustomEndCap = PenCapProvider.GetInheritanceRepresentation(); g.DrawLines(pen, new[] { imageTip, imageEnd }); } else { cap = new AdjustableArrowCap(10, 12); pen.CustomStartCap = cap; g.DrawLines(pen, new[] { imageTip, imageEnd }); cap.Dispose(); } } else { g.DrawLines(pen, new[] { imageTip, imageEnd }); } } }
private void drawArrow(Graphics g, int x, int y, int x2, int y2) { Pen p = new Pen(Color.Black, 2);//此处设置颜色和宽度 AdjustableArrowCap aac = new AdjustableArrowCap(5, 5); //p.CustomStartCap = aac; p.CustomEndCap = aac; g.DrawLine(p, x, y, x2, y2); p.Dispose(); aac.Dispose(); }