请单击以进行评分并提供反馈
MSDN
MSDN Library
.NET 开发
.NET Framework
Geometry 类
全部折叠/全部展开 全部折叠
此页面仅适用于
Microsoft Visual Studio 2008/.NET Framework 3.5

同时提供下列产品的其他版本:
.NET Framework 类库
Geometry 类

更新:2007 年 11 月

从此抽象基类派生的类定义几何形状。Geometry 对象可用于剪裁和呈现二维图形数据以及对其进行点击测试。

命名空间:  System.Windows.Media
程序集:  PresentationCore(在 PresentationCore.dll 中)

Visual Basic(声明)
<LocalizabilityAttribute(LocalizationCategory.None, Readability := Readability.Unreadable)> _
<TypeConverterAttribute(GetType(GeometryConverter))> _
Public MustInherit Class Geometry _
    Inherits Animatable _
    Implements IFormattable
Visual Basic (用法)
Dim instance As Geometry
C#
[LocalizabilityAttribute(LocalizationCategory.None, Readability = Readability.Unreadable)]
[TypeConverterAttribute(typeof(GeometryConverter))]
public abstract class Geometry : Animatable, 
    IFormattable
Visual C++
[LocalizabilityAttribute(LocalizationCategory::None, Readability = Readability::Unreadable)]
[TypeConverterAttribute(typeof(GeometryConverter))]
public ref class Geometry abstract : public Animatable, 
    IFormattable
J#
/** @attribute LocalizabilityAttribute(LocalizationCategory.None, Readability = Readability.Unreadable) */
/** @attribute TypeConverterAttribute(GeometryConverter) */
public abstract class Geometry extends Animatable implements IFormattable
JScript
public abstract class Geometry extends Animatable implements IFormattable
XAML
该类为抽象类;有关 XAML 中可用的派生的非抽象类,请参见 继承层次结构。

几何图形与形状比较

System.Windows.Shapes..::.Shape 类拥有 Geometry 及其派生类所没有的 FillStroke 和其他呈现属性。Shape 类是一个 FrameworkElement,因而会参与布局系统;其派生类可用作支持 UIElement 子项的任何元素的内容。

另一方面,Geometry 类只定义形状的几何图形,无法呈现自身。由于它十分简单,因而用途更加广泛。

可冻结功能:由于继承自 Freezable 类,因此 Geometry 类提供了一些特殊功能:Geometry 对象可按资源中的方式进行声明、在多个对象之间共享、设为只读以提高性能、进行克隆以及设为线程安全。有关 Freezable 对象提供的不同功能的更多信息,请参见 Freezable 对象概述

对继承者的说明:

虽然此类是抽象的,但不能公开扩展它。

此示例演示如何使用 Geometry 对象创建复合形状并使用 Path 元素显示这些复合形状。在下面的示例中,将 LineGeometryEllipseGeometryRectangleGeometryGeometryGroup 一起使用以创建复合形状。然后,使用 Path 元素绘制这些几何图形。

C#
<!-- Displays the geometry. --> 
<Path Stroke="Black" StrokeThickness="1" Fill="#CCCCFF">
  <Path.Data>

    <!-- Creates a composite shape from three geometries. -->
    <GeometryGroup FillRule="EvenOdd">
      <LineGeometry StartPoint="10,10" EndPoint="50,30" />
      <EllipseGeometry Center="40,70" RadiusX="30" RadiusY="30" />              
      <RectangleGeometry Rect="30,55 100 30" />
    </GeometryGroup>
  </Path.Data>
</Path>
C#
// Create a Path to be drawn to the screen.
Path myPath = new Path();
myPath.Stroke = Brushes.Black;
myPath.StrokeThickness = 1;
SolidColorBrush mySolidColorBrush = new SolidColorBrush();
mySolidColorBrush.Color = Color.FromArgb(255, 204, 204, 255);
myPath.Fill = mySolidColorBrush;

// Create the line geometry to add to the Path
LineGeometry myLineGeometry = new LineGeometry();
myLineGeometry.StartPoint = new Point(10, 10);
myLineGeometry.EndPoint = new Point(50, 30);

// Create the ellipse geometry to add to the Path
EllipseGeometry myEllipseGeometry = new EllipseGeometry();
myEllipseGeometry.Center = new Point(40, 70);
myEllipseGeometry.RadiusX = 30;
myEllipseGeometry.RadiusY = 30;

// Create a rectangle geometry to add to the Path
RectangleGeometry myRectGeometry = new RectangleGeometry();
myRectGeometry.Rect = new Rect(30, 55, 100, 30);

// Add all the geometries to a GeometryGroup.
GeometryGroup myGeometryGroup = new GeometryGroup();
myGeometryGroup.Children.Add(myLineGeometry);
myGeometryGroup.Children.Add(myEllipseGeometry);
myGeometryGroup.Children.Add(myRectGeometry);

myPath.Data = myGeometryGroup;

// Add path shape to the UI.
StackPanel mainPanel = new StackPanel();
mainPanel.Children.Add(myPath);
this.Content = mainPanel;

下图显示在上一示例中创建的形状。

复合几何图形

使用 GeometryGroup 创建的复合几何图形

更复杂的形状(如多边形和含曲线线段的形状)可使用 PathGeometry 创建。有关演示如何使用 PathGeometry 创建形状的示例,请参见如何:使用 PathGeometry 创建形状。 尽管此示例使用 Path 元素向屏幕呈现形状,但 Geometry 对象也可用来描述 GeometryDrawingDrawingContext 的内容。此外,这些对象还可用于剪裁和命中测试。

此示例摘自一个更大的示例;有关完整的示例,请参见几何图形示例

更多代码

如何:使用 PathGeometry 创建形状此示例演示如何使用 PathGeometry 类创建形状。PathGeometry 对象由一个或多个 PathFigure 对象组成;每个 PathFigure 都表示一个不同的“图形”或形状。每个 PathFigure 自身又由一个或多个 PathSegment 对象组成,每个对象均表示图形或形状的已连接部分。线段类型包括 LineSegmentArcSegmentBezierSegment
如何:对 EllipseGeometry 进行动画处理本示例演示如何对 Path 元素内的 Geometry 进行动画处理。在下面的示例中,PointAnimation 用于对 EllipseGeometryCenter 进行动画处理。
此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。

Windows Vista

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

.NET Framework

受以下版本支持:3.5、3.0
社区内容   什么是社区内容?
添加新内容 RSS  批注
Processing
© 2010 Microsoft Corporation 版权所有。 保留所有权利 | 商标 | 隐私权声明
Page view tracker