728x90
728x170
▶ 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
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] Frame 클래스 : Navigate 메소드를 사용해 페이지 이동하기 (0) | 2020.08.08 |
---|---|
[C#/WPF] Button 엘리먼트 : Background 속성 사용하기 (0) | 2020.08.08 |
[C#/WPF] BulletDecorator 엘리먼트 사용하기 (0) | 2020.08.08 |
[C#/WPF] DrawingVisual 클래스 사용하기 (0) | 2020.08.07 |
[C#/WPF] UIElement 엘리먼트 : Clip 속성 사용하기 (0) | 2020.08.07 |
[C#/WPF] Storyboard 클래스 : 이미지 슬라이드 쇼 보여주기 (0) | 2020.08.06 |
[C#/WPF] WriteableBitmap 클래스 : 비트맵 픽셀 조작하기 (0) | 2020.08.06 |
[C#/WPF] Trigger 엘리먼트 : 버튼 클릭시 배경색 변경하기 (0) | 2020.08.06 |
[C#/WPF] Mouse 클래스 : GetPosition 정적 메소드를 사용해 마우스 위치 구하기 (0) | 2020.08.06 |
[C#/WPF] SystemParameters 클래스 : IsMouseWheelPresent 정적 속성을 사용해 마우스 휠 존재 여부 구하기 (0) | 2020.08.06 |