728x90
반응형
728x170
■ RichTextBox 클래스에서 선택한 문자열의 폰트, 폰트 크기, 폰트 스타일 등을 구하는 방법을 보여준다.
▶ RichTextBox 클래스 : 선택 문자열의 속성값 구하기 예제 (C#)
FontFamily fontFamily = GetSelectionStringPropertyValue<FontFamily>(richTextBox, FlowDocument.FontFamilyProperty);
double fontSize = GetSelectionStringPropertyValue<double>(richTextBox, FlowDocument.FontSizeProperty);
FontWeight fontWeight = GetSelectionStringPropertyValue<FontWeight>(richTextBox, FlowDocument.FontWeightProperty);
FontStyle fontStyle = GetSelectionStringPropertyValue<FontStyle>(richTextBox, FlowDocument.FontStyleProperty);
Brush backgroundBrush = GetSelectionStringPropertyValue<Brush>(richTextBox, FlowDocument.BackgroundProperty);
Brush foregroundBrush = GetSelectionStringPropertyValue<Brush>(richTextBox, FlowDocument.ForegroundProperty);
TextAlignment textAlignment = GetSelectionStringPropertyValue<TextAlignment>(richTextBox, FlowDocument.TextAlignmentProperty);
▶ RichTextBox 클래스 : 선택 문자열의 속성값 구하기 (C#)
using System.Windows;
using System.Windows.Controls;
#region 선택 문자열의 속성값 구하기 - GetSelectionStringPropertyValue<TValue>(richTextBox, dependencyProperty)
/// <summary>
/// 선택 문자열의 속성값 구하기
/// </summary>
/// <typeparam name="TPropertyValue">속성 값 타입</typeparam>
/// <param name="richTextBox">RichTextBox 객체</param>
/// <param name="dependencyProperty">DependencyProperty 객체</param>
/// <returns>속성 값</returns>
public TPropertyValue GetSelectionStringPropertyValue<TPropertyValue>(RichTextBox richTextBox, DependencyProperty dependencyProperty)
{
return (TPropertyValue)(richTextBox.Selection.GetPropertyValue(dependencyProperty));
}
#endregion
728x90
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] x:Class 속성 사용하기 (0) | 2014.01.08 |
---|---|
[C#/WPF] FrameworkTemplate 클래스 : XAML 구하기 (0) | 2014.01.08 |
[C#/WPF] XML 텍스트 리더에서 객체 생성하기 (0) | 2014.01.08 |
[C#/WPF] IValueConverter 인터페이스 : 타입→타입명 변환자 사용하기 (0) | 2014.01.05 |
[C#/WPF] BitmapImage 클래스 : URI에서 비트맵 이미지 구하기 (0) | 2014.01.03 |
[C#/WPF] RichTextBox 클래스 : 선택 문자열의 속성값 설정하기 (0) | 2014.01.03 |
[C#/WPF] FlowDocument 클래스 : 특정 범위의 문자열 지우기 (0) | 2014.01.03 |
[C#/WPF] MediaPlayer 클래스 : 재생시 Slider 연동하기 (0) | 2014.01.02 |
[C#/WPF] MediaPlayer 클래스 : Slider 객체 연동하기 (0) | 2013.12.30 |
[C#/WPF] MediaPlayer 클래스 : 조작하기 (0) | 2013.12.30 |
댓글을 달아 주세요