I want to draw a line and show the arrow cap at the 'tail' of the line, like this:
Here is what I tried. The arrow cap is placed at the line's end, but its direction is not correct. It's coming downwards while I want it upwards like in the above image.
AdjustableArrowCap bigArrow = new AdjustableArrowCap(5, 5);
Pen p = new Pen(Color.Black, 2);
p.CustomEndCap = bigArrow;
g.DrawLine(p, X, Y, X, 50);
This is a workaround, using a one-pixel extra line, but I think will do the job:
var img = new System.Drawing.Bitmap(200, 200);
using (var g = System.Drawing.Graphics.FromImage(img)) {
using (var p1 = new System.Drawing.Pen(System.Drawing.Color.Black, 2),
p2 = new System.Drawing.Pen(System.Drawing.Color.Black, 2)) {
using (var bigArrow = new AdjustableArrowCap(5, 5)) {
p2.CustomEndCap = bigArrow;
g.DrawLine(p1, 25, 50, 25, 100);
g.DrawLine(p2, 25, 100, 25, 99);
}
}
}
Here is my output:
This one uses CustomLineCap
, it's not perfect but hopefully will give you a good direction
Graphics g= e.Graphics;
using (var path = new GraphicsPath()) {
path.AddLine(new Point(-4, 4), new Point(4, 4));
path.AddLine(new Point(4, 4), new Point(0, -1));
path.AddLine(new Point(0, -1), new Point(-4, 4));
using (var cap = new CustomLineCap(path, null))
using (var customCapPen = new Pen(Color.Black, 2) {CustomEndCap = cap}) { g.DrawLine(customCapPen, 10, 10, 10, 50); }
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.