gpt4 book ai didi

c# - 如何在对象上画一条虚线?

转载 作者:可可西里 更新时间:2023-11-01 07:49:02 26 4
gpt4 key购买 nike

我在我的 Windows 窗体上的控件上画一条线,如下所示:

            // Get Graphics object from chart
Graphics graph = e.ChartGraphics.Graphics;

PointF point1 = PointF.Empty;
PointF point2 = PointF.Empty;

// Set Maximum and minimum points
point1.X = -110;
point1.Y = -110;
point2.X = 122;
point2.Y = 122;

// Convert relative coordinates to absolute coordinates.
point1 = e.ChartGraphics.GetAbsolutePoint(point1);
point2 = e.ChartGraphics.GetAbsolutePoint(point2);

// Draw connection line
graph.DrawLine(new Pen(Color.Yellow, 3), point1, point2);

我想知道是否可以绘制虚线(点线)而不是常规实线?

最佳答案

一旦你figure out the formatting就很简单了定义破折号:

float[] dashValues = { 5, 2, 15, 4 };
Pen blackPen = new Pen(Color.Black, 5);
blackPen.DashPattern = dashValues;
e.Graphics.DrawLine(blackPen, new Point(5, 5), new Point(405, 5));

float 组中的数字代表不同颜色的短划线长度。因此,对于一个简单的 2 像素破折号(黑色)和两个像素破折号,您的阵列看起来像: {2,2} 然后重复该模式。如果你想要 5 宽的破折号和 2 像素的空间,你可以使用 {5,2}

在您的代码中它看起来像:

// Get Graphics object from chart
Graphics graph = e.ChartGraphics.Graphics;

PointF point1 = PointF.Empty;
PointF point2 = PointF.Empty;

// Set Maximum and minimum points
point1.X = -110;
point1.Y = -110;
point2.X = 122;
point2.Y = 122;

// Convert relative coordinates to absolute coordinates.
point1 = e.ChartGraphics.GetAbsolutePoint(point1);
point2 = e.ChartGraphics.GetAbsolutePoint(point2);

// Draw (dashed) connection line
float[] dashValues = { 4, 2 };
Pen dashPen= new Pen(Color.Yellow, 3);
dashPen.DashPattern = dashValues;
graph.DrawLine(dashPen, point1, point2);

关于c# - 如何在对象上画一条虚线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6100573/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com