첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
본 블로그는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 블로그 콘텐츠 향상을 위해 쓰여집니다.

728x90
반응형
728x170

TestProject.zip
다운로드

▶ 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"
    Width="800"
    Height="600"
    Title="DrawingContext 클래스 : DrawDrawing 메소드를 사용해 드로잉 그리기"
    Background="Transparent">
    <Grid Name="grid" >
    </Grid>
</Window>

 

▶ MainWindow.xaml.cs

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

namespace TestProject
{
    /// <summary>
    /// 메인 윈도우
    /// </summary>
    public partial class MainWindow : Window
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 펜
        /// </summary>
        private Pen pen;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainWindow()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();

            this.pen = new Pen(Brushes.Blue, 10);

            this.pen.Freeze();
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Protected

        #region 렌더링시 처리하기 - OnRender(drawingContext)

        /// <summary>
        /// 렌더링시 처리하기
        /// </summary>
        /// <param name="drawingContext">그리기 컨텍스트</param>
        protected override void OnRender(DrawingContext drawingContext)
        {
            drawingContext.DrawRectangle
            (
                Brushes.White,
                null,
                new Rect
                (
                    0,
                    0,
                    this.grid.ActualWidth,
                    this.grid.ActualHeight
                )
            );

            EllipseGeometry ellipseGeometry = new EllipseGeometry();

            ellipseGeometry.Center  = new Point(this.grid.ActualWidth / 2, this.grid.ActualHeight / 2);
            ellipseGeometry.RadiusX = 200;
            ellipseGeometry.RadiusY = 200;

            GeometryDrawing geometryDrawing = new GeometryDrawing();

            geometryDrawing.Pen   = this.pen;
            geometryDrawing.Brush = Brushes.Red;

            geometryDrawing.Geometry = ellipseGeometry;

            drawingContext.DrawDrawing(geometryDrawing);
        }

        #endregion
    }
}
728x90
반응형
그리드형
Posted by 사용자 icodebroker
TAG , , ,

댓글을 달아 주세요