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

TestProject.zip
다운로드

▶ CustomEllipse.cs

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

namespace TestProject
{
    /// <summary>
    /// 커스텀 타원
    /// </summary>
    public class CustomEllipse : FrameworkElement
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 포맷 텍스트
        /// </summary>
        private FormattedText formattedText;

        #endregion

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

        #region 생성자 - CustomEllipse()

        /// <summary>
        /// 생성자
        /// </summary>
        public CustomEllipse()
        {
            this.formattedText = new FormattedText
            (
                "Hello, ellipse!",
                CultureInfo.CurrentCulture,
                FlowDirection,
                new Typeface("Times New Roman Italic"),
                48,
                Brushes.White
            );
        }

        #endregion

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

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

        /// <summary>
        /// 렌더링시 처리하기
        /// </summary>
        /// <param name="drawingContext">그리기 컨텍스트</param>
        protected override void OnRender(DrawingContext drawingContext)
        {
            drawingContext.DrawEllipse
            (
                Brushes.Blue                                          ,
                new Pen(Brushes.Red, 24)                              ,
                new Point(RenderSize.Width / 2, RenderSize.Height / 2),
                RenderSize.Width  / 2                                 ,
                RenderSize.Height / 2
            );

            drawingContext.PushClip(new RectangleGeometry(new Rect(new Point(0, 0), RenderSize)));

            Point textPoint = new Point
            (
                (RenderSize.Width  - this.formattedText.Width ) / 2,
                (RenderSize.Height - this.formattedText.Height) / 2
            );

            drawingContext.DrawText(this.formattedText, textPoint);
        }

        #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="DrawingContext 클래스 : PushClip 메소드를 사용해 클리핑 영역 설정하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Grid>
        <local:CustomEllipse
            Margin="10" />
    </Grid>
</Window>
728x90
그리드형(광고전용)
Posted by icodebroker
,