728x90
반응형
728x170
▶ 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
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] 이미지 롤 애니메이션(Roll Animation) 사용하기 (0) | 2021.02.08 |
---|---|
[C#/WPF] UI 자동화 사용하기 (0) | 2021.02.08 |
[C#/WPF] 모니터 추가/제거시 이벤트 처리하기 (0) | 2021.02.08 |
[C#/WPF] Shape 클래스 : 커스텀 호(Arc) 만들기 (0) | 2021.02.07 |
[C#/WPF] DrawingContext 클래스 : DrawGlyphRun 메소드를 사용해 텍스트 그리기 (0) | 2021.02.07 |
[C#/WPF] TextBlock 엘리먼트 : Text 속성에서 개행 문자 사용하기 (0) | 2021.02.07 |
[C#/WPF] StreamGeometry 클래스 사용하기 (0) | 2021.02.07 |
[C#/WPF] FrameworkElement 클래스 : 커스텀 엘리먼트 만들기 (0) | 2021.02.07 |
[C#/WPF] DrawingVisual 클래스 : 커스텀 비주얼 만들기 (0) | 2021.02.07 |
[C#/WPF] LinearGradientBrush 엘리먼트 : MappingMode 속성을 사용해 절대 좌표 설정하기 (0) | 2021.02.07 |
댓글을 달아 주세요