.NET Framework 类库
Polygon 类

更新:2007 年 11 月

绘制一个多边形,它是形成闭合形状的一系列相互连接的直接。

命名空间:  System.Windows.Shapes
程序集:  PresentationFramework(在 PresentationFramework.dll 中)
用于 XAML 的 XMLNS:http://schemas.microsoft.com/winfx/xaml/presentation

语法

Visual Basic(声明)
Public NotInheritable Class Polygon _
    Inherits Shape
Visual Basic (用法)
Dim instance As Polygon
C#
public sealed class Polygon : Shape
Visual C++
public ref class Polygon sealed : public Shape
J#
public final class Polygon extends Shape
JScript
public final class Polygon extends Shape
XAML 对象元素用法
<Polygon .../>
备注

此对象与 Polyline 对象类似,不同的是,此对象必须是闭合的形状。

示例

下面的示例演示如何使用代码创建 Polygon 元素并设置其属性。有关完整的示例,请参见 WPF 形状库示例

Visual Basic
' Add a Polygon Element
Dim myPolygon As New Polygon()
myPolygon.Stroke = Brushes.Black
myPolygon.Fill = Brushes.LightSeaGreen
myPolygon.StrokeThickness = 2
myPolygon.HorizontalAlignment = HorizontalAlignment.Left
myPolygon.VerticalAlignment = VerticalAlignment.Center
Dim Point1 As New System.Windows.Point(1, 50)
Dim Point2 As New System.Windows.Point(10, 80)
Dim Point3 As New System.Windows.Point(50, 50)
Dim myPointCollection As New PointCollection()
myPointCollection.Add(Point1)
myPointCollection.Add(Point2)
myPointCollection.Add(Point3)
myPolygon.Points = myPointCollection
myGrid.Children.Add(myPolygon)
C#
//Add the Polygon Element
myPolygon = new Polygon();
myPolygon.Stroke = System.Windows.Media.Brushes.Black;
myPolygon.Fill = System.Windows.Media.Brushes.LightSeaGreen;
myPolygon.StrokeThickness = 2;
myPolygon.HorizontalAlignment = HorizontalAlignment.Left;
myPolygon.VerticalAlignment = VerticalAlignment.Center;
System.Windows.Point Point1 = new System.Windows.Point(1, 50);
System.Windows.Point Point2 = new System.Windows.Point(10,80);
System.Windows.Point Point3 = new System.Windows.Point(50,50);
PointCollection myPointCollection = new PointCollection();
myPointCollection.Add(Point1);
myPointCollection.Add(Point2);
myPointCollection.Add(Point3);
myPolygon.Points = myPointCollection;
myGrid.Children.Add(myPolygon);

更多代码

如何:使用多边形元素来绘制闭合形状此示例演示如何使用 Polygon 元素绘制闭合形状。若要绘制闭合形状,请创建一个 Polygon 元素,并使用其 Points 属性指定形状的顶点。系统将自动绘制一条线连接第一个点和最后一个点。最后,指定 Fill 和/或 Stroke
继承层次结构

System..::.Object
  System.Windows.Threading..::.DispatcherObject
    System.Windows..::.DependencyObject
      System.Windows.Media..::.Visual
        System.Windows..::.UIElement
          System.Windows..::.FrameworkElement
            System.Windows.Shapes..::.Shape
              System.Windows.Shapes..::.Polygon
线程安全

此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。
平台

Windows Vista

.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求

版本信息

.NET Framework

受以下版本支持:3.5、3.0
另请参见

参考

其他资源

标记 :


Page view tracker