FormattedText 클래스

정의

WPF(Windows Presentation Foundation) 애플리케이션에서 텍스트를 그리기 위한 수준이 낮은 제어를 제공합니다.

public ref class FormattedText
public class FormattedText
type FormattedText = class
Public Class FormattedText
상속
FormattedText

예제

다음 예제에서는 개체를 FormattedText 만든 다음 텍스트에 여러 서식 스타일을 적용합니다.

protected override void OnRender(DrawingContext drawingContext)
{
    string testString = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor";

    // Create the initial formatted text string.
    FormattedText formattedText = new FormattedText(
        testString,
        CultureInfo.GetCultureInfo("en-us"),
        FlowDirection.LeftToRight,
        new Typeface("Verdana"),
        32,
        Brushes.Black);

    // Set a maximum width and height. If the text overflows these values, an ellipsis "..." appears.
    formattedText.MaxTextWidth = 300;
    formattedText.MaxTextHeight = 240;

    // Use a larger font size beginning at the first (zero-based) character and continuing for 5 characters.
    // The font size is calculated in terms of points -- not as device-independent pixels.
    formattedText.SetFontSize(36 * (96.0 / 72.0), 0, 5);

    // Use a Bold font weight beginning at the 6th character and continuing for 11 characters.
    formattedText.SetFontWeight(FontWeights.Bold, 6, 11);

    // Use a linear gradient brush beginning at the 6th character and continuing for 11 characters.
    formattedText.SetForegroundBrush(
                            new LinearGradientBrush(
                            Colors.Orange,
                            Colors.Teal,
                            90.0),
                            6, 11);

    // Use an Italic font style beginning at the 28th character and continuing for 28 characters.
    formattedText.SetFontStyle(FontStyles.Italic, 28, 28);

    // Draw the formatted text string to the DrawingContext of the control.
    drawingContext.DrawText(formattedText, new Point(10, 0));
}
Protected Overrides Sub OnRender(ByVal drawingContext As DrawingContext)
    Dim testString As String = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor"

    ' Create the initial formatted text string.
    Dim formattedText As New FormattedText(testString, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, New Typeface("Verdana"), 32, Brushes.Black)

    ' Set a maximum width and height. If the text overflows these values, an ellipsis "..." appears.
    formattedText.MaxTextWidth = 300
    formattedText.MaxTextHeight = 240

    ' Use a larger font size beginning at the first (zero-based) character and continuing for 5 characters.
    ' The font size is calculated in terms of points -- not as device-independent pixels.
    formattedText.SetFontSize(36 * (96.0 / 72.0), 0, 5)

    ' Use a Bold font weight beginning at the 6th character and continuing for 11 characters.
    formattedText.SetFontWeight(FontWeights.Bold, 6, 11)

    ' Use a linear gradient brush beginning at the 6th character and continuing for 11 characters.
    formattedText.SetForegroundBrush(New LinearGradientBrush(Colors.Orange, Colors.Teal, 90.0), 6, 11)

    ' Use an Italic font style beginning at the 28th character and continuing for 28 characters.
    formattedText.SetFontStyle(FontStyles.Italic, 28, 28)

    ' Draw the formatted text string to the DrawingContext of the control.
    drawingContext.DrawText(formattedText, New Point(10, 0))
End Sub

설명

개체 FormattedText 를 사용하면 텍스트의 각 문자에 개별적으로 서식을 지정할 수 있는 여러 줄 텍스트를 그릴 수 있습니다. 다음 예에서는 여러 서식이 적용된 텍스트를 보여줍니다.

FormattedText 개체를 사용하여 표시되는 텍스트 서식이 지정된 텍스트 문자열의 예

WPF FormattedText 의 텍스트 기능 측면에서 텍스트를 그래픽 요소로 처리하므로 "하위 수준"으로 간주됩니다. WPF에서 텍스트의 다른 측면은 텍스트 전용 컨트롤의 컨텍스트에서 텍스트를 처리(TextBlock, TextBox흐름 문서 모델 구현(Flow 문서 개요 참조) 또는 XPS 문서 모델 지원(WPF의 문서 참조).

대부분의 setter 메서드 FormattedText 는 지원 TextElement되는 연결된 속성과 유사하지만 TextElement 연결된 속성은 흐름 또는 XPS에 대한 상위 수준 텍스트 지원에 적용됩니다.

생성자

FormattedText(String, CultureInfo, FlowDirection, Typeface, Double, Brush)
사용되지 않습니다.

지정된 텍스트, 문화권, 흐름 방향, 서체, 글꼴 크기 및 브러시를 사용하여 FormattedText 클래스의 새 인스턴스를 초기화합니다.

FormattedText(String, CultureInfo, FlowDirection, Typeface, Double, Brush, Double)

지정된 텍스트, 문화권, 흐름 방향, 서체, 글꼴 크기, 전경 브러시 및 pixelsPerDip 값으로 FormattedText 클래스의 새 인스턴스를 초기화합니다.

FormattedText(String, CultureInfo, FlowDirection, Typeface, Double, Brush, NumberSubstitution)
사용되지 않습니다.

지정한 텍스트, 문화권, 흐름 방향, 서체, 글꼴 크기, 브러시 및 숫자 대체 동작을 사용하여 FormattedText 클래스의 새 인스턴스를 초기화합니다.

FormattedText(String, CultureInfo, FlowDirection, Typeface, Double, Brush, NumberSubstitution, Double)

지정된 텍스트, 문화권, 흐름 방향, 서체, 글꼴 크기, 브러시 숫자 대체 동작, pixelsPerDip 값을 사용하여 FormattedText 클래스의 새 인스턴스를 초기화합니다.

FormattedText(String, CultureInfo, FlowDirection, Typeface, Double, Brush, NumberSubstitution, TextFormattingMode)
사용되지 않습니다.

지정한 텍스트, 문화권, 흐름 방향, 서체, 글꼴 크기, 브러시, 숫자 대체 동작 및 텍스트 서식 모드를 사용하여 FormattedText 클래스의 새 인스턴스를 초기화합니다.

FormattedText(String, CultureInfo, FlowDirection, Typeface, Double, Brush, NumberSubstitution, TextFormattingMode, Double)

지정된 텍스트, 문화권, 흐름 방향, 서체, 글꼴 크기, 브러시 숫자 대체 동작, pixelsPerDip 값을 사용하여 FormattedText 클래스의 새 인스턴스를 초기화합니다.

속성

Baseline

FormattedText 개체의 첫 줄 맨 위에서 첫 줄 기준선까지의 거리를 가져옵니다.

Extent

첫 줄 맨 위에 그려진 픽셀에서 마지막 줄 맨 아래에 그려진 픽셀까지의 거리를 가져옵니다.

FlowDirection

FlowDirection 개체의 FormattedText을 가져오거나 설정합니다.

Height

FormattedText 개체의 첫 줄 맨 위에서 마지막 줄 맨 아래까지의 거리를 가져옵니다.

LineHeight

줄 높이 또는 텍스트 줄 간의 줄 간격을 가져옵니다.

MaxLineCount

표시할 최대 줄 수를 가져오거나 설정합니다. MaxLineCount를 초과하는 텍스트는 표시되지 않습니다.

MaxTextHeight

텍스트 열의 최대 높이를 가져오거나 설정합니다.

MaxTextWidth

텍스트 줄에 대한 최대 텍스트 너비(길이)를 가져오거나 설정합니다.

MinWidth

지정한 텍스트 내용 전체를 포함할 수 있는 최소 텍스트 너비를 가져옵니다.

OverhangAfter

마지막 텍스트 줄의 아래에서 맨 아래에 그려진 픽셀까지의 거리를 가져옵니다.

OverhangLeading

선행 맞춤 지점에서 줄 맨 앞에 그려진 픽셀까지의 최대 거리를 가져옵니다.

OverhangTrailing

잉크가 지정된 맨 뒤의 픽셀에서 줄의 후행 맞춤 지점까지의 최대 거리를 가져옵니다.

PixelsPerDip

텍스트가 렌더링되어야 하는 PixelsPerDip를 가져오거나 설정합니다.

Text

표시할 텍스트 문자열을 가져옵니다.

TextAlignment

FormattedText 개체 내의 텍스트 맞춤을 가져오거나 설정합니다.

Trimming

텍스트 생략을 나타내는 방법을 가져오거나 설정합니다.

Width

후행 공백 문자를 제외한 줄의 선행 맞춤 지점과 후행 맞춤 지점 간의 너비를 가져옵니다.

WidthIncludingTrailingWhitespace

후행 공백 문자를 포함한 줄의 선행 맞춤 지점과 후행 맞춤 지점 간의 너비를 가져옵니다.

메서드

BuildGeometry(Point)

모든 문자 모양과 텍스트 장식을 포함하여 서식 있는 텍스트를 나타내는 Geometry 개체를 반환합니다.

BuildHighlightGeometry(Point)

서식 있는 텍스트의 강조 표시 경계 상자를 나타내는 Geometry 개체를 반환합니다.

BuildHighlightGeometry(Point, Int32, Int32)

서식 있는 텍스트의 지정한 부분 문자열에 대한 강조 표시 경계 상자를 나타내는 Geometry 개체를 반환합니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetMaxTextWidths()

텍스트 너비의 배열을 검색합니다. 배열의 각 요소는 순차적 텍스트 줄의 최대 텍스트 너비를 나타냅니다.

GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
SetCulture(CultureInfo)

CultureInfo 개체의 전체 문자 집합에 대한 FormattedText를 설정합니다.

SetCulture(CultureInfo, Int32, Int32)

CultureInfo 개체의 지정한 하위 문자 집합에 대한 FormattedText를 설정합니다.

SetFontFamily(FontFamily)

FormattedText 개체에 대한 글꼴 패밀리를 설정합니다.

SetFontFamily(FontFamily, Int32, Int32)

FormattedText 개체의 지정한 하위 문자 집합에 대한 글꼴 패밀리를 설정합니다.

SetFontFamily(String)

FormattedText 개체의 전체 문자 집합에 대한 글꼴 패밀리를 설정합니다.

SetFontFamily(String, Int32, Int32)

FormattedText 개체의 지정한 하위 문자 집합에 대한 글꼴 패밀리를 설정합니다.

SetFontSize(Double)

FormattedText 개체의 전체 문자 집합에 대한 글꼴 크기를 설정합니다.

SetFontSize(Double, Int32, Int32)

FormattedText 개체의 지정한 하위 문자 집합에 대한 글꼴 크기를 설정합니다.

SetFontStretch(FontStretch)

FormattedText 개체의 전체 문자 집합에 대한 글꼴 늘이기 값을 설정합니다.

SetFontStretch(FontStretch, Int32, Int32)

FormattedText 개체의 지정한 하위 문자 집합에 대한 글꼴 늘이기 값을 설정합니다.

SetFontStyle(FontStyle)

FormattedText 개체의 전체 문자 집합에 대한 글꼴 스타일을 설정합니다.

SetFontStyle(FontStyle, Int32, Int32)

FormattedText 개체의 지정한 하위 문자 집합에 대한 글꼴 스타일을 설정합니다.

SetFontTypeface(Typeface)

FormattedText 개체의 전체 문자 집합에 대한 글꼴 서체를 설정합니다.

SetFontTypeface(Typeface, Int32, Int32)

FormattedText 개체의 지정한 하위 문자 집합에 대한 글꼴 서체를 설정합니다.

SetFontWeight(FontWeight)

FormattedText 개체의 전체 문자 집합에 대한 글꼴 두께를 설정합니다.

SetFontWeight(FontWeight, Int32, Int32)

FontWeight 개체 내의 지정한 텍스트에 대한 FormattedText를 변경합니다.

SetForegroundBrush(Brush)

전체 Brush 개체에 대한 전경 FormattedText를 변경합니다.

SetForegroundBrush(Brush, Int32, Int32)

Brush 개체 내의 지정한 텍스트에 대한 전경 FormattedText를 변경합니다.

SetMaxTextWidths(Double[])

줄 단위로 FormattedText 내의 최대 텍스트 너비 배열을 설정합니다. 배열의 각 요소는 순차적 텍스트 줄의 최대 텍스트 너비를 나타냅니다.

SetNumberSubstitution(NumberSubstitution)

FormattedText 개체의 전체 문자 집합에 대한 숫자 대체 동작을 설정합니다.

SetNumberSubstitution(NumberSubstitution, Int32, Int32)

FormattedText 개체 내의 지정한 텍스트에 대한 숫자 대체 동작을 설정합니다.

SetTextDecorations(TextDecorationCollection)

TextDecorationCollection 개체의 전체 문자 집합에 대한 FormattedText를 설정합니다.

SetTextDecorations(TextDecorationCollection, Int32, Int32)

TextDecorationCollection 개체 내의 지정한 텍스트에 대한 FormattedText을 설정합니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보