次の方法で共有


方法 : PathGeometry で LineSegment を作成する

この例では、線分を作成する方法を示します。 線分を作成するには、PathGeometryPathFigure、および LineSegment の各クラスを使用します。

使用例

次の例では、LineSegment を (10, 50) から (200, 70) まで描画します。 結果として得られる LineSegment を次の図に示します。座標を示すために、グリッド背景を追加しています。

(10,50) から (200,700) まで描画された LineSegment

PathFigure 内の LineSegment

[xaml]

Extensible Application Markup Language (XAML) では、属性の構文を使用してパスを記述できます。

<Path Stroke="Black" StrokeThickness="1"  
  Data="M 10,50 L 200,70" />

[xaml]

(この属性構文は、実際には PathGeometry の軽量バージョンである StreamGeometry を作成します。 詳細については、「パス マークアップ構文」のページを参照してください。)

XAML では、オブジェクト要素構文を使用して線分を描画することもできます。 次の例は、前の XAML の例と同じです。

            Dim myPathFigure As New PathFigure()
            myPathFigure.StartPoint = New Point(10, 50)

            Dim myLineSegment As New LineSegment()
            myLineSegment.Point = New Point(200, 70)

            Dim myPathSegmentCollection As New PathSegmentCollection()
            myPathSegmentCollection.Add(myLineSegment)

            myPathFigure.Segments = myPathSegmentCollection

            Dim myPathFigureCollection As New PathFigureCollection()
            myPathFigureCollection.Add(myPathFigure)

            Dim myPathGeometry As New PathGeometry()
            myPathGeometry.Figures = myPathFigureCollection

            Dim myPath As New Path()
            myPath.Stroke = Brushes.Black
            myPath.StrokeThickness = 1
            myPath.Data = myPathGeometry
PathFigure myPathFigure = new PathFigure();
myPathFigure.StartPoint = new Point(10, 50);

LineSegment myLineSegment = new LineSegment();
myLineSegment.Point = new Point(200, 70);

PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();
myPathSegmentCollection.Add(myLineSegment);

myPathFigure.Segments = myPathSegmentCollection;

PathFigureCollection myPathFigureCollection = new PathFigureCollection();
myPathFigureCollection.Add(myPathFigure);

PathGeometry myPathGeometry = new PathGeometry();
myPathGeometry.Figures = myPathFigureCollection;

Path myPath = new Path();
myPath.Stroke = Brushes.Black;
myPath.StrokeThickness = 1;
myPath.Data = myPathGeometry;
<Path Stroke="Black" StrokeThickness="1">
  <Path.Data>
    <PathGeometry>
      <PathFigure StartPoint="10,50">
        <LineSegment Point="200,70" />
      </PathFigure>
    </PathGeometry>
  </Path.Data>
</Path>

この例は、より大きなサンプルの一部です。サンプル全体については、ジオメトリのサンプルを参照してください。

参照

参照

PathFigure

PathGeometry

GeometryDrawing

Path

概念

ジオメトリの概要