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

▶ RichTextBox 클래스 : 선택 문자열의 속성값 구하기 예제

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);

 

728x90

 

▶ RichTextBox 클래스 : 선택 문자열의 속성값 구하기

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
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요