[英]Drawing lines in WPF on DrawingContext with outer lines
You would have to draw two lines between identical points on top of each other, the lower with a thicker pen, the upper with a thinner pen. 您将必须在彼此顶部的相同点之间绘制两条线,下部使用较粗的笔,上部使用较细的笔。
Pen background = new Pen(Brushes.Black, 5);
Pen foreground = new Pen(Brushes.White, 3);
drawingContext.DrawLine(background, new Point(100, 100), new Point(200, 200));
drawingContext.DrawLine(foreground, new Point(100, 100), new Point(200, 200));
This lines look at lot better when you also define the pen line caps: 当您还定义笔线帽时,这些线看起来更好:
Pen background = new Pen
{
Brush = Brushes.Black,
Thickness = 5,
StartLineCap = PenLineCap.Round,
EndLineCap = PenLineCap.Round
};
Pen foreground = new Pen
{
Brush = Brushes.White,
Thickness = 3,
StartLineCap = PenLineCap.Round,
EndLineCap = PenLineCap.Round
};
With an extension method like this 使用这样的扩展方法
public static class DrawingContextExtensions
{
public static void DrawLine(this DrawingContext drawingContext,
Pen background, Pen foreground, Point start, Point end)
{
drawingContext.DrawLine(background, start, end);
drawingContext.DrawLine(foreground, start, end);
}
}
you could do the drawing in one call: 您可以在一个电话中绘制图纸:
drawingContext.DrawLine(background, foreground, new Point(100, 100), new Point(200, 200));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.