如何画一条带箭头的线?
我有以下代码,它用一个(非常)小箭头绘制一条线...
private void Form1_Paint(object sender, PaintEventArgs e)
{
Pen p = new Pen(Color.Black);
p.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
e.Graphics.DrawLine(p, 10, 10, 100, 100);
p.Dispose();
}
我想绘制一个大箭头(圆形,正方形,三角形等...... .),保持相同的线宽。
是否可以?
I have the following code, that draws a line with a (very) small arrow...
private void Form1_Paint(object sender, PaintEventArgs e)
{
Pen p = new Pen(Color.Black);
p.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
e.Graphics.DrawLine(p, 10, 10, 100, 100);
p.Dispose();
}
I want to draw a big arrow (circle, square, triangle etc...), keeping the same line width.
Is it possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您希望将
CustomLineCap
与GraphicsPath
一起使用。下面是一个示例:您想要用一条从上到下、从 (0, 0) 开始的线来“设计”您的帽子,以获得正确的坐标。
编辑:我只是想提一下,您还可以使用
AdjustableArrowCap
绘制特定尺寸的箭头并填充它,但因为您提到了其他形状的要求,所以我'我用过 CustomLineCap。You'd want to use a
CustomLineCap
with aGraphicsPath
. Here's an example:You want to "design" your cap with a line going top-to-bottom and from (0, 0) to get the correct coordinates.
EDIT: I just wanted to mention that you can also use
AdjustableArrowCap
to draw an arrow of a specific size and fill it but because you mentioned the requirement for other shapes, I've used a CustomLineCap.正如 TheCloudlessSky 提到的,
AdjustableArrowCap
可用于绘制箭头。As TheCloudlessSky mentioned,
AdjustableArrowCap
can be used to draw the arrow head.