共用方式為


如何:使用 LineGeometry 建立線條

這個範例示範如何使用 LineGeometry 類別來描述一行。 LineGeometry是由其起點和終點所定義。

範例

下列範例示範如何建立和轉譯 LineGeometry 。 元素 Path 是用來轉譯線條。 由於線條沒有區域, Path 因此不會指定 物件的 Fill ,而是 Stroke 使用 和 StrokeThickness 屬性。

<Path Stroke="Black" StrokeThickness="1" >
  <Path.Data>
    <LineGeometry StartPoint="10,20" EndPoint="100,130" />
  </Path.Data>
</Path>
LineGeometry myLineGeometry = new LineGeometry();
myLineGeometry.StartPoint = new Point(10,20);
myLineGeometry.EndPoint = new Point(100,130);

Path myPath = new Path();
myPath.Stroke = Brushes.Black;
myPath.StrokeThickness = 1;
myPath.Data = myLineGeometry;
Dim myLineGeometry As New LineGeometry()
myLineGeometry.StartPoint = New Point(10,20)
myLineGeometry.EndPoint = New Point(100,130)

Dim myPath As New Path()
myPath.Stroke = Brushes.Black
myPath.StrokeThickness = 1
myPath.Data = myLineGeometry

A LineGeometry
從 (10,20) 繪製到 (100,130) 的 LineGeometry

其他簡單的幾何類別包括 LineGeometryEllipseGeometry 。 這些幾何,以及更複雜的幾何,也可以使用 或 StreamGeometry 來建立 PathGeometry 。 如需詳細資訊,請參閱 幾何概觀

另請參閱