첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
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 클래스 : DrawRoundedRectangle 메소드를 사용해 라운드 사각형 그리기"
    Background="Transparent">
    <Grid Name="grid" >
    </Grid>
</Window>

 

728x90

 

▶ 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
                )
            );

            Rect rectangle = new Rect
            (
                100,
                100,
                this.grid.ActualWidth  - 200,
                this.grid.ActualHeight - 200
            );

            drawingContext.DrawRoundedRectangle(Brushes.LightBlue, this.pen, rectangle, 50, 50);
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요