Share via


방법: 복합 도형 만들기

이 예제는 Geometry 개체를 사용하여 복합 도형을 만들고 Path 요소를 사용하여 표시하는 방법을 보여 줍니다. 다음 예제에서 LineGeometry, EllipseGeometry, RectangleGeometryGeometryGroup과 함께 복합 도형을 만드는 데 사용됩니다. 그런 다음 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;
' Create a Path to be drawn to the screen.
Dim myPath As New Path()
myPath.Stroke = Brushes.Black
myPath.StrokeThickness = 1
Dim mySolidColorBrush As New SolidColorBrush()
mySolidColorBrush.Color = Color.FromArgb(255, 204, 204, 255)
myPath.Fill = mySolidColorBrush

' Create the line geometry to add to the Path
Dim myLineGeometry As New LineGeometry()
myLineGeometry.StartPoint = New Point(10, 10)
myLineGeometry.EndPoint = New Point(50, 30)

' Create the ellipse geometry to add to the Path
Dim myEllipseGeometry As New EllipseGeometry()
myEllipseGeometry.Center = New Point(40, 70)
myEllipseGeometry.RadiusX = 30
myEllipseGeometry.RadiusY = 30

' Create a rectangle geometry to add to the Path
Dim myRectGeometry As New RectangleGeometry()
myRectGeometry.Rect = New Rect(30, 55, 100, 30)

' Add all the geometries to a GeometryGroup.
Dim myGeometryGroup As New GeometryGroup()
myGeometryGroup.Children.Add(myLineGeometry)
myGeometryGroup.Children.Add(myEllipseGeometry)
myGeometryGroup.Children.Add(myRectGeometry)

myPath.Data = myGeometryGroup

' Add path shape to the UI.
Dim mainPanel As New StackPanel()
mainPanel.Children.Add(myPath)
Me.Content = mainPanel

다음 그림은 이전 예제에서 만든 도형을 보여 줍니다.

GeometryGroup을 사용해 만든 복합 기하 도형
복합 기하 도형

다각형이나 곡선 세그먼트가 있는 도형 같이 보다 복잡한 도형은 PathGeometry를 사용하여 만들 수 있습니다. PathGeometry를 사용하여 도형을 만드는 방법을 보여 주는 예제는 PathGeometry를 사용하여 도형 만들기를 참조하세요. 이 예제에서는 Path 요소를 사용하여 도형을 화면에 렌더링하지만 Geometry 개체는 GeometryDrawing 또는 DrawingContext의 내용을 설명하는 데 사용할 수도 있습니다. 클리핑 및 적중 테스트에도 사용할 수 있습니다.

이 예제는 더 큰 샘플에 속합니다. 전체 샘플을 보려면 기하 도형 샘플을 참조하세요.