728x90
반응형
728x170
▶ 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="외곽선 텍스트 사용하기"
FontFamily="나눔고딕코딩"
FontSize="16">
<Grid>
<Label Name="label"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="48"
FontWeight="Bold"
Foreground="White"
Content="외곽선 텍스트 입니다." />
</Grid>
</Window>
728x90
▶ MainWindow.xaml.cs
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
namespace TestProject
{
/// <summary>
/// 메인 윈도우
/// </summary>
public partial class MainWindow : Window
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainWindow()
/// <summary>
/// 생성자
/// </summary>
public MainWindow()
{
InitializeComponent();
ApplyOutlineText(this.label, Brushes.Gray);
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
#region 윤곽선 텍스트 적용하기 - ApplyOutlineText(label, outlineBrush)
/// <summary>
/// 윤곽선 텍스트 적용하기
/// </summary>
/// <param name="label">레이블</param>
/// <param name="outlineBrush">외곽선 브러시</param>
private void ApplyOutlineText(Label label, Brush outlineBrush)
{
FormattedText formattedText = new FormattedText
(
label.Content.ToString(),
System.Threading.Thread.CurrentThread.CurrentCulture,
FlowDirection.LeftToRight,
new Typeface(label.FontFamily, label.FontStyle, label.FontWeight, label.FontStretch),
label.FontSize,
Brushes.Black
);
formattedText.TextAlignment = TextAlignment.Center;
Geometry geometry = formattedText.BuildGeometry(new Point(0, 0));
PathGeometry pathGeometry = geometry.GetFlattenedPathGeometry();
Path path = new Path();
path.Stroke = outlineBrush;
path.StrokeThickness = 2;
path.Fill = label.Foreground;
path.Stretch = Stretch.Fill;
Canvas canvas = new Canvas();
canvas.Children.Add(path);
label.Content = canvas;
Canvas.SetTop (path, (canvas.ActualHeight - formattedText.Extent) / 2);
Canvas.SetLeft(path, (canvas.ActualWidth - formattedText.Width ) / 2);
path.Data = pathGeometry;
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] ListView 클래스 : 항목 드래그시 스크롤하기 (0) | 2019.06.29 |
---|---|
[C#/WPF] ListView 클래스 : 항목 드래그 & 드롭 사용하기 (0) | 2019.06.29 |
[C#/WPF] 시스템 메뉴 표시하기 (0) | 2019.06.29 |
[C#/WPF] 리소스 폰트 사용하기 (0) | 2019.06.29 |
[C#/WPF] RadioButton 클래스 : 열거형 바인딩하기 (0) | 2019.06.29 |
[C#/WPF] 외곽선 텍스트 사용하기 (0) | 2019.06.29 |
[C#/WPF] 외곽선 텍스트 사용하기 (0) | 2019.06.29 |
[C#/WPF] DropShadowEffect 클래스 : 텍스트 그림자 효과 적용하기 (0) | 2019.06.29 |
[C#/WPF] FontHelper 클래스 사용하기 (0) | 2019.06.28 |
[C#/WPF] FontDialog 클래스 : WinForm 폰트 대화 상자 사용하기 (0) | 2019.06.28 |
[C#/WPF] 듀얼 모니터 보조 화면 창 열기 (0) | 2019.06.28 |
댓글을 달아 주세요