첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
0.01MB

▶ CustomShape.cs

using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;

namespace TestProject
{
    /// <summary>
    /// 커스텀 도형
    /// </summary>
    public class CustomShape : Shape
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Protected

        #region 정의 지오메트리 - DefiningGeometry

        /// <summary>
        /// 정의 지오메트리
        /// </summary>
        protected override Geometry DefiningGeometry
        {
            get
            {
                return GetGeometry();
            }
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region 지오메트리 구하기 - GetGeometry()

        /// <summary>
        /// 지오메트리 구하기
        /// </summary>
        /// <returns>지오메트리</returns>
        private Geometry GetGeometry()
        {
            StreamGeometry streamGeometry = new StreamGeometry();

            using(StreamGeometryContext streamGeometryContext = streamGeometry.Open())
            {
                streamGeometryContext.BeginFigure
                (
                    new Point(50.0, 50.0),
                    false,
                    true
                );

                streamGeometryContext.ArcTo
                (
                    new Point(75.0, 75.0),
                    new Size(10.0, 20.0),
                    0.0,
                    false,
                    SweepDirection.Clockwise,
                    true,
                    true
                );

                streamGeometryContext.ArcTo
                (
                    new Point(100.0, 100.0),
                    new Size(10.0, 20.0),
                    0.0,
                    false,
                    SweepDirection.Clockwise,
                    true,
                    true
                );
            }
 
            return streamGeometry;
        }

        #endregion
    }
}

 

728x90

 

▶ MainWindow.xaml

<Window x:Class="TestProject.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:TestProject"
    Width="800"
    Height="600"
    Title="Shape 클래스 : DefiningGeometry 속성을 사용해 커스텀 도형 만들기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Grid>
        <Border
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
            BorderThickness="1"
            BorderBrush="DarkGray">
            <local:CustomShape
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
                StrokeThickness="10"
                Stroke="Orange" />
        </Border>
    </Grid>
</Window>
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요