wpf使用代码 画一个弧线
时间: 2024-01-21 07:19:57 浏览: 26
您可以使用`Path`和`PathGeometry`来绘制弧形。以下是一个示例代码,可以绘制一个从 0 度到 90 度的圆弧:
```csharp
Path path = new Path();
path.Stroke = Brushes.Black;
path.StrokeThickness = 2;
PathGeometry pathGeometry = new PathGeometry();
PathFigure pathFigure = new PathFigure();
pathFigure.StartPoint = new Point(100, 100);
ArcSegment arcSegment = new ArcSegment();
arcSegment.Point = new Point(200, 100);
arcSegment.Size = new Size(100, 100);
arcSegment.IsLargeArc = false;
arcSegment.SweepDirection = SweepDirection.Clockwise;
pathFigure.Segments.Add(arcSegment);
pathGeometry.Figures.Add(pathFigure);
path.Data = pathGeometry;
canvas.Children.Add(path);
```
在此示例中,我们创建了一个 `Path` 实例,并设置其 `Stroke` 和 `StrokeThickness` 属性。然后,我们创建了一个 `PathGeometry` 实例,并向其添加一个 `PathFigure`。我们设置 `PathFigure` 的 `StartPoint` 为 (100, 100)。接下来,我们创建了一个 `ArcSegment` 实例,并将其添加到 `PathFigure` 的 `Segments` 集合中。我们设置 `ArcSegment` 的 `Point` 为 (200, 100),表示弧线的结束点。我们还设置了弧线的半径为 (100, 100),并将 `IsLargeArc` 属性设置为 `false`,表示绘制小弧线。最后,我们将 `PathGeometry` 分配给 `Path` 的 `Data` 属性。最后一步是将 `Path` 添加到一个 `Canvas` 控件中以显示它。
您可以根据需要更改 `StartPoint`、`Point`、`Size` 和 `IsLargeArc` 属性来绘制不同的弧线。