|
|
[C#]
CustomLineCap(GraphicsPath fill, GraphicsPath stroke);
CustomLineCap(GraphicsPath fill, GraphicsPath stroke, LineCap cap);
[Visual Basic]
Sub New(fill As GraphicsPath, stroke As GraphicsPath)
Sub New(fill As GraphicsPath, stroke As GraphicsPath, cap As LineCap)
|
|
|
|
[C#]
using (Bitmap bm = new Bitmap(600, 600)) {
using (Graphics graphics = Graphics.FromImage(bm)) {
GraphicsPath big = new GraphicsPath();
big.AddEllipse(-2, -2, 4, 4);
GraphicsPath small = new GraphicsPath();
small.AddEllipse(-1, -1, 2, 2);
Pen pen = new Pen(Color.Black, 20);
pen.CustomStartCap = new CustomLineCap(null, big);
pen.CustomEndCap = new CustomLineCap(small, null);
for (int i = 0; i < 3; i++) {
pen.CustomStartCap.BaseInset = i;
pen.CustomEndCap.BaseInset = i;
pen.Color = Color.Red;
graphics.DrawLine(pen, 100, 100, 200, 200);
pen.Color = Color.Green;
graphics.DrawLine(pen, 200, 200, 100, 400);
pen.Color = Color.Blue;
graphics.DrawLine(pen, 100, 400, 200, 500);
graphics.TranslateTransform(150, 0);
}
}
bm.Save(Server.MapPath("IG8_CustomLineCap.png"));
}
The code here uses two different custom line caps. We vary the
BaseInset to show how it affects the end point of the line. The
final output is shown below. If you are interested in designs for
custom end points HTML Arrows is a good place to start.

IG8_CustomLineCap.png
|