다음을 통해 공유


방법: 복합 도형 만들기

업데이트: 2007년 11월

이 예제에서는 Geometry 개체를 사용하여 복합 도형을 만들고 Path 요소를 사용하여 이를 표시하는 방법을 보여 줍니다. 다음 예제에서는 LineGeometry, EllipseGeometryRectangleGeometryGeometryGroup과 함께 사용하여 복합 도형을 만듭니다. 그런 다음 Path 요소를 사용하여 기하 도형을 그립니다.

예제

<!-- 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>
// 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 개체를 사용하여 GeometryDrawing 또는 DrawingContext의 콘텐츠를 설명할 수도 있습니다. 또한 클리핑 및 적중 테스트에도 사용할 수 있습니다.

이 예제는 보다 큰 샘플의 일부입니다. 전체 샘플은 기하 도형 샘플을 참조하십시오.