TextRenderer.MeasureText 메서드

정의

지정된 글꼴을 사용하여 그릴 때 지정된 텍스트를 측정합니다.

오버로드

MeasureText(String, Font, Size, TextFormatFlags)

텍스트의 초기 경계 사각형을 만들 지정된 크기를 사용하여 지정된 글꼴과 서식 명령으로 그릴 때 지정된 텍스트의 크기(픽셀)를 제공합니다.

MeasureText(ReadOnlySpan<Char>, Font, Size, TextFormatFlags)

텍스트의 초기 경계 사각형을 만들 지정된 크기를 사용하여 지정된 글꼴과 서식 명령으로 그릴 때 지정된 텍스트의 크기(픽셀)를 제공합니다.

MeasureText(IDeviceContext, String, Font, Size)

텍스트의 초기 경계 사각형을 만들 지정된 크기를 사용하여 지정된 디바이스 컨텍스트에 지정된 글꼴로 그릴 때 지정된 텍스트의 크기(픽셀)를 제공합니다.

MeasureText(IDeviceContext, ReadOnlySpan<Char>, Font, Size)

텍스트의 초기 경계 사각형을 만들 지정된 크기를 사용하여 지정된 디바이스 컨텍스트에 지정된 글꼴로 그릴 때 지정된 텍스트의 크기(픽셀)를 제공합니다.

MeasureText(String, Font, Size)

초기 경계 사각형을 만들 지정된 크기를 사용하여 지정된 글꼴로 그릴 때 지정된 텍스트의 크기(픽셀)를 제공합니다.

MeasureText(IDeviceContext, ReadOnlySpan<Char>, Font)

지정된 디바이스 컨텍스트에서 지정된 글꼴을 사용하여 그린 지정된 텍스트의 크기(픽셀)를 제공합니다.

MeasureText(IDeviceContext, String, Font)

지정된 디바이스 컨텍스트에서 지정된 글꼴을 사용하여 그린 지정된 텍스트의 크기(픽셀)를 제공합니다.

MeasureText(String, Font)

지정된 글꼴을 사용하여 그릴 때 지정된 텍스트의 크기(픽셀)를 제공합니다.

MeasureText(ReadOnlySpan<Char>, Font)

지정된 글꼴을 사용하여 그릴 때 지정된 텍스트의 크기(픽셀)를 제공합니다.

MeasureText(IDeviceContext, ReadOnlySpan<Char>, Font, Size, TextFormatFlags)

텍스트의 초기 경계 사각형을 만들 지정된 크기를 사용하여 지정된 디바이스 컨텍스트, 글꼴 및 서식 명령으로 그릴 때 지정된 텍스트의 크기(픽셀)를 제공합니다.

MeasureText(ReadOnlySpan<Char>, Font, Size)

초기 경계 사각형을 만들 지정된 크기를 사용하여 지정된 글꼴로 그릴 때 지정된 텍스트의 크기(픽셀)를 제공합니다.

MeasureText(IDeviceContext, String, Font, Size, TextFormatFlags)

텍스트의 초기 경계 사각형을 만들 지정된 크기를 사용하여 지정된 디바이스 컨텍스트, 글꼴 및 서식 명령으로 그릴 때 지정된 텍스트의 크기(픽셀)를 제공합니다.

MeasureText(String, Font, Size, TextFormatFlags)

텍스트의 초기 경계 사각형을 만들 지정된 크기를 사용하여 지정된 글꼴과 서식 명령으로 그릴 때 지정된 텍스트의 크기(픽셀)를 제공합니다.

public:
 static System::Drawing::Size MeasureText(System::String ^ text, System::Drawing::Font ^ font, System::Drawing::Size proposedSize, System::Windows::Forms::TextFormatFlags flags);
public static System.Drawing.Size MeasureText (string text, System.Drawing.Font font, System.Drawing.Size proposedSize, System.Windows.Forms.TextFormatFlags flags);
public static System.Drawing.Size MeasureText (string? text, System.Drawing.Font? font, System.Drawing.Size proposedSize, System.Windows.Forms.TextFormatFlags flags);
static member MeasureText : string * System.Drawing.Font * System.Drawing.Size * System.Windows.Forms.TextFormatFlags -> System.Drawing.Size
Public Shared Function MeasureText (text As String, font As Font, proposedSize As Size, flags As TextFormatFlags) As Size

매개 변수

text
String

측정할 텍스트입니다.

font
Font

측정한 텍스트에 적용할 Font입니다.

proposedSize
Size

초기 경계 사각형의 Size입니다.

flags
TextFormatFlags

측정한 텍스트에 적용할 서식 명령입니다.

반환

지정된 text와 형식을 사용하여 그린 fontSize(픽셀)입니다.

예제

다음 코드 예제 중 하나를 사용 하는 방법에 설명 합니다 MeasureText 메서드. 이 예제를 실행 하려면 호출을 Windows Form에 코드를 붙여넣은 DrawALineOfText 폼의 Paint 이벤트 처리기를 전달 e 으로 PaintEventArgs입니다.

private static void DrawALineOfText(PaintEventArgs e)
{
    // Declare strings to render on the form.
    string[] stringsToPaint = { "Tail", "Spin", " Toys" };

    // Declare fonts for rendering the strings.
    Font[] fonts = { new Font("Arial", 14, FontStyle.Regular), 
        new Font("Arial", 14, FontStyle.Italic), 
        new Font("Arial", 14, FontStyle.Regular) };

    Point startPoint = new Point(10, 10);

    // Set TextFormatFlags to no padding so strings are drawn together.
    TextFormatFlags flags = TextFormatFlags.NoPadding;

    // Declare a proposed size with dimensions set to the maximum integer value.
    Size proposedSize = new Size(int.MaxValue, int.MaxValue);

    // Measure each string with its font and NoPadding value and 
    // draw it to the form.
    for (int i = 0; i < stringsToPaint.Length; i++)
    {
        Size size = TextRenderer.MeasureText(e.Graphics, stringsToPaint[i], 
            fonts[i], proposedSize, flags);
        Rectangle rect = new Rectangle(startPoint, size);
        TextRenderer.DrawText(e.Graphics, stringsToPaint[i], fonts[i],
            startPoint, Color.Black, flags);
        startPoint.X += size.Width;
    }
}
Private Sub DrawALineOfText(ByVal e As PaintEventArgs)
    ' Declare strings to render on the form.
    Dim stringsToPaint() As String = {"Tail", "Spin", " Toys"}

    ' Declare fonts for rendering the strings.
    Dim fonts() As Font = {New Font("Arial", 14, FontStyle.Regular), _
        New Font("Arial", 14, FontStyle.Italic), _
        New Font("Arial", 14, FontStyle.Regular)}

    Dim startPoint As New Point(10, 10)

    ' Set TextFormatFlags to no padding so strings are drawn together.
    Dim flags As TextFormatFlags = TextFormatFlags.NoPadding

    ' Declare a proposed size with dimensions set to the maximum integer value.
    Dim proposedSize As Size = New Size(Integer.MaxValue, Integer.MaxValue)

    ' Measure each string with its font and NoPadding value and draw it to the form.
    For i As Integer = 0 To stringsToPaint.Length - 1
        Dim size As Size = TextRenderer.MeasureText(e.Graphics, _
            stringsToPaint(i), fonts(i), proposedSize, flags)
        Dim rect As Rectangle = New Rectangle(startPoint, size)
        TextRenderer.DrawText(e.Graphics, stringsToPaint(i), fonts(i), _
            startPoint, Color.Black, flags)
        startPoint.X += size.Width
    Next
End Sub

설명

MeasureText 사용 하는 proposedSizeflags 텍스트 크기를 결정할 때 높이 너비의 관계를 나타내기 위해 매개 변수입니다. 측정 하는 경우 텍스트 줄의 경우는 proposedSize 매개 변수를 나타냅니다는 Size 보다 큰 높이 차원 Int32.MaxValue, 반환 된 Size 텍스트의 실제 높이 맞게 조정 됩니다.

DrawText 매개 변수를 사용하는 TextFormatFlags 오버로드 중 하나를 사용하여 텍스트를 그리는 방법을 조작할 수 있습니다. 예를 들어, TextRenderer의 기본 동작은 걸친 모양의 문자를 표시하기 위해 그린 텍스트의 경계 사각형에 여백을 추가하는 것입니다. 이러한 추가 공간 없이 한 줄의 텍스트를 그려야 하는 경우 DrawTextMeasureText 매개 변수를 사용하는 SizeTextFormatFlags의 버전을 사용해야 합니다. 예제를 보려면 MeasureText(IDeviceContext, String, Font, Size, TextFormatFlags)를 참조하세요.

참고

이 오버 로드 MeasureText(String, Font, Size, TextFormatFlags) 무시를 TextFormatFlags 의 값 NoPadding 또는 LeftAndRightPadding합니다. 기본값이 아닌 안쪽 여백 값을 지정 하는 경우의 오버 로드를 사용 해야 MeasureText(IDeviceContext, String, Font, Size, TextFormatFlags) 를 사용 하는 한 IDeviceContext 개체입니다.

적용 대상

MeasureText(ReadOnlySpan<Char>, Font, Size, TextFormatFlags)

텍스트의 초기 경계 사각형을 만들 지정된 크기를 사용하여 지정된 글꼴과 서식 명령으로 그릴 때 지정된 텍스트의 크기(픽셀)를 제공합니다.

public:
 static System::Drawing::Size MeasureText(ReadOnlySpan<char> text, System::Drawing::Font ^ font, System::Drawing::Size proposedSize, System::Windows::Forms::TextFormatFlags flags);
public static System.Drawing.Size MeasureText (ReadOnlySpan<char> text, System.Drawing.Font? font, System.Drawing.Size proposedSize, System.Windows.Forms.TextFormatFlags flags);
static member MeasureText : ReadOnlySpan<char> * System.Drawing.Font * System.Drawing.Size * System.Windows.Forms.TextFormatFlags -> System.Drawing.Size
Public Shared Function MeasureText (text As ReadOnlySpan(Of Char), font As Font, proposedSize As Size, flags As TextFormatFlags) As Size

매개 변수

text
ReadOnlySpan<Char>

측정할 텍스트입니다.

font
Font

측정한 텍스트에 적용할 Font입니다.

proposedSize
Size

초기 경계 사각형의 Size입니다.

flags
TextFormatFlags

측정한 텍스트에 적용할 서식 명령입니다.

반환

지정된 text와 형식을 사용하여 그린 fontSize(픽셀)입니다.

예외

적용 대상

MeasureText(IDeviceContext, String, Font, Size)

텍스트의 초기 경계 사각형을 만들 지정된 크기를 사용하여 지정된 디바이스 컨텍스트에 지정된 글꼴로 그릴 때 지정된 텍스트의 크기(픽셀)를 제공합니다.

public:
 static System::Drawing::Size MeasureText(System::Drawing::IDeviceContext ^ dc, System::String ^ text, System::Drawing::Font ^ font, System::Drawing::Size proposedSize);
public static System.Drawing.Size MeasureText (System.Drawing.IDeviceContext dc, string text, System.Drawing.Font font, System.Drawing.Size proposedSize);
public static System.Drawing.Size MeasureText (System.Drawing.IDeviceContext dc, string? text, System.Drawing.Font? font, System.Drawing.Size proposedSize);
static member MeasureText : System.Drawing.IDeviceContext * string * System.Drawing.Font * System.Drawing.Size -> System.Drawing.Size
Public Shared Function MeasureText (dc As IDeviceContext, text As String, font As Font, proposedSize As Size) As Size

매개 변수

dc
IDeviceContext

텍스트를 측정할 디바이스 컨텍스트입니다.

text
String

측정할 텍스트입니다.

font
Font

측정한 텍스트에 적용할 Font입니다.

proposedSize
Size

초기 경계 사각형의 Size입니다.

반환

지정된 text를 사용하여 그린 fontSize(픽셀)입니다.

예외

dc이(가) null인 경우

예제

다음 코드 예제 중 하나를 사용 하는 방법에 설명 합니다 MeasureText 메서드. 이 예제를 실행 하려면 호출을 Windows Form에 코드를 붙여넣은 DrawALineOfText 폼의 Paint 이벤트 처리기를 전달 e 으로 PaintEventArgs입니다.

private static void DrawALineOfText(PaintEventArgs e)
{
    // Declare strings to render on the form.
    string[] stringsToPaint = { "Tail", "Spin", " Toys" };

    // Declare fonts for rendering the strings.
    Font[] fonts = { new Font("Arial", 14, FontStyle.Regular), 
        new Font("Arial", 14, FontStyle.Italic), 
        new Font("Arial", 14, FontStyle.Regular) };

    Point startPoint = new Point(10, 10);

    // Set TextFormatFlags to no padding so strings are drawn together.
    TextFormatFlags flags = TextFormatFlags.NoPadding;

    // Declare a proposed size with dimensions set to the maximum integer value.
    Size proposedSize = new Size(int.MaxValue, int.MaxValue);

    // Measure each string with its font and NoPadding value and 
    // draw it to the form.
    for (int i = 0; i < stringsToPaint.Length; i++)
    {
        Size size = TextRenderer.MeasureText(e.Graphics, stringsToPaint[i], 
            fonts[i], proposedSize, flags);
        Rectangle rect = new Rectangle(startPoint, size);
        TextRenderer.DrawText(e.Graphics, stringsToPaint[i], fonts[i],
            startPoint, Color.Black, flags);
        startPoint.X += size.Width;
    }
}
Private Sub DrawALineOfText(ByVal e As PaintEventArgs)
    ' Declare strings to render on the form.
    Dim stringsToPaint() As String = {"Tail", "Spin", " Toys"}

    ' Declare fonts for rendering the strings.
    Dim fonts() As Font = {New Font("Arial", 14, FontStyle.Regular), _
        New Font("Arial", 14, FontStyle.Italic), _
        New Font("Arial", 14, FontStyle.Regular)}

    Dim startPoint As New Point(10, 10)

    ' Set TextFormatFlags to no padding so strings are drawn together.
    Dim flags As TextFormatFlags = TextFormatFlags.NoPadding

    ' Declare a proposed size with dimensions set to the maximum integer value.
    Dim proposedSize As Size = New Size(Integer.MaxValue, Integer.MaxValue)

    ' Measure each string with its font and NoPadding value and draw it to the form.
    For i As Integer = 0 To stringsToPaint.Length - 1
        Dim size As Size = TextRenderer.MeasureText(e.Graphics, _
            stringsToPaint(i), fonts(i), proposedSize, flags)
        Dim rect As Rectangle = New Rectangle(startPoint, size)
        TextRenderer.DrawText(e.Graphics, stringsToPaint(i), fonts(i), _
            startPoint, Color.Black, flags)
        startPoint.X += size.Width
    Next
End Sub

설명

합니다 MeasureText 메서드는 proposedSize 텍스트 크기를 결정할 때 높이 너비의 관계를 나타내기 위해 매개 변수입니다. 측정 하는 경우 텍스트 줄의 경우는 proposedSize 매개 변수를 나타냅니다는 Size 보다 큰 높이 차원 Int32.MaxValue, 반환 된 Size 텍스트의 실제 높이 맞게 조정 됩니다.

적용 대상

MeasureText(IDeviceContext, ReadOnlySpan<Char>, Font, Size)

텍스트의 초기 경계 사각형을 만들 지정된 크기를 사용하여 지정된 디바이스 컨텍스트에 지정된 글꼴로 그릴 때 지정된 텍스트의 크기(픽셀)를 제공합니다.

public:
 static System::Drawing::Size MeasureText(System::Drawing::IDeviceContext ^ dc, ReadOnlySpan<char> text, System::Drawing::Font ^ font, System::Drawing::Size proposedSize);
public static System.Drawing.Size MeasureText (System.Drawing.IDeviceContext dc, ReadOnlySpan<char> text, System.Drawing.Font? font, System.Drawing.Size proposedSize);
static member MeasureText : System.Drawing.IDeviceContext * ReadOnlySpan<char> * System.Drawing.Font * System.Drawing.Size -> System.Drawing.Size
Public Shared Function MeasureText (dc As IDeviceContext, text As ReadOnlySpan(Of Char), font As Font, proposedSize As Size) As Size

매개 변수

dc
IDeviceContext

텍스트를 측정할 디바이스 컨텍스트입니다.

text
ReadOnlySpan<Char>

측정할 텍스트입니다.

font
Font

측정한 텍스트에 적용할 Font입니다.

proposedSize
Size

초기 경계 사각형의 Size입니다.

반환

지정된 text를 사용하여 그린 fontSize(픽셀)입니다.

예외

dc이(가) null인 경우.

적용 대상

MeasureText(String, Font, Size)

초기 경계 사각형을 만들 지정된 크기를 사용하여 지정된 글꼴로 그릴 때 지정된 텍스트의 크기(픽셀)를 제공합니다.

public:
 static System::Drawing::Size MeasureText(System::String ^ text, System::Drawing::Font ^ font, System::Drawing::Size proposedSize);
public static System.Drawing.Size MeasureText (string text, System.Drawing.Font font, System.Drawing.Size proposedSize);
public static System.Drawing.Size MeasureText (string? text, System.Drawing.Font? font, System.Drawing.Size proposedSize);
static member MeasureText : string * System.Drawing.Font * System.Drawing.Size -> System.Drawing.Size
Public Shared Function MeasureText (text As String, font As Font, proposedSize As Size) As Size

매개 변수

text
String

측정할 텍스트입니다.

font
Font

측정한 텍스트에 적용할 Font입니다.

proposedSize
Size

초기 경계 사각형의 Size입니다.

반환

지정된 text를 사용하여 그린 fontSize(픽셀)입니다.

예제

다음 코드 예제 중 하나를 사용 하는 방법에 설명 합니다 MeasureText 메서드. 이 예제를 실행 하려면 호출을 Windows Form에 코드를 붙여넣은 DrawALineOfText 폼의 Paint 이벤트 처리기를 전달 e 으로 PaintEventArgs입니다.

private static void DrawALineOfText(PaintEventArgs e)
{
    // Declare strings to render on the form.
    string[] stringsToPaint = { "Tail", "Spin", " Toys" };

    // Declare fonts for rendering the strings.
    Font[] fonts = { new Font("Arial", 14, FontStyle.Regular), 
        new Font("Arial", 14, FontStyle.Italic), 
        new Font("Arial", 14, FontStyle.Regular) };

    Point startPoint = new Point(10, 10);

    // Set TextFormatFlags to no padding so strings are drawn together.
    TextFormatFlags flags = TextFormatFlags.NoPadding;

    // Declare a proposed size with dimensions set to the maximum integer value.
    Size proposedSize = new Size(int.MaxValue, int.MaxValue);

    // Measure each string with its font and NoPadding value and 
    // draw it to the form.
    for (int i = 0; i < stringsToPaint.Length; i++)
    {
        Size size = TextRenderer.MeasureText(e.Graphics, stringsToPaint[i], 
            fonts[i], proposedSize, flags);
        Rectangle rect = new Rectangle(startPoint, size);
        TextRenderer.DrawText(e.Graphics, stringsToPaint[i], fonts[i],
            startPoint, Color.Black, flags);
        startPoint.X += size.Width;
    }
}
Private Sub DrawALineOfText(ByVal e As PaintEventArgs)
    ' Declare strings to render on the form.
    Dim stringsToPaint() As String = {"Tail", "Spin", " Toys"}

    ' Declare fonts for rendering the strings.
    Dim fonts() As Font = {New Font("Arial", 14, FontStyle.Regular), _
        New Font("Arial", 14, FontStyle.Italic), _
        New Font("Arial", 14, FontStyle.Regular)}

    Dim startPoint As New Point(10, 10)

    ' Set TextFormatFlags to no padding so strings are drawn together.
    Dim flags As TextFormatFlags = TextFormatFlags.NoPadding

    ' Declare a proposed size with dimensions set to the maximum integer value.
    Dim proposedSize As Size = New Size(Integer.MaxValue, Integer.MaxValue)

    ' Measure each string with its font and NoPadding value and draw it to the form.
    For i As Integer = 0 To stringsToPaint.Length - 1
        Dim size As Size = TextRenderer.MeasureText(e.Graphics, _
            stringsToPaint(i), fonts(i), proposedSize, flags)
        Dim rect As Rectangle = New Rectangle(startPoint, size)
        TextRenderer.DrawText(e.Graphics, stringsToPaint(i), fonts(i), _
            startPoint, Color.Black, flags)
        startPoint.X += size.Width
    Next
End Sub

설명

합니다 MeasureText 메서드는 proposedSize 텍스트 크기를 결정할 때 높이 너비의 관계를 나타내기 위해 매개 변수입니다. 측정 하는 경우 텍스트 줄의 경우는 proposedSize 매개 변수를 나타냅니다는 Size 보다 큰 높이 차원 Int32.MaxValue, 반환 된 Size 텍스트의 실제 높이 맞게 조정 됩니다.

적용 대상

MeasureText(IDeviceContext, ReadOnlySpan<Char>, Font)

지정된 디바이스 컨텍스트에서 지정된 글꼴을 사용하여 그린 지정된 텍스트의 크기(픽셀)를 제공합니다.

public:
 static System::Drawing::Size MeasureText(System::Drawing::IDeviceContext ^ dc, ReadOnlySpan<char> text, System::Drawing::Font ^ font);
public static System.Drawing.Size MeasureText (System.Drawing.IDeviceContext dc, ReadOnlySpan<char> text, System.Drawing.Font? font);
static member MeasureText : System.Drawing.IDeviceContext * ReadOnlySpan<char> * System.Drawing.Font -> System.Drawing.Size
Public Shared Function MeasureText (dc As IDeviceContext, text As ReadOnlySpan(Of Char), font As Font) As Size

매개 변수

dc
IDeviceContext

텍스트를 측정할 디바이스 컨텍스트입니다.

text
ReadOnlySpan<Char>

측정할 텍스트입니다.

font
Font

측정한 텍스트에 적용할 Font입니다.

반환

지정된 디바이스 컨텍스트에서 지정된 font를 사용하여 그린 textSize(픽셀)입니다.

예외

dc이(가) null인 경우.

적용 대상

MeasureText(IDeviceContext, String, Font)

지정된 디바이스 컨텍스트에서 지정된 글꼴을 사용하여 그린 지정된 텍스트의 크기(픽셀)를 제공합니다.

public:
 static System::Drawing::Size MeasureText(System::Drawing::IDeviceContext ^ dc, System::String ^ text, System::Drawing::Font ^ font);
public static System.Drawing.Size MeasureText (System.Drawing.IDeviceContext dc, string text, System.Drawing.Font font);
public static System.Drawing.Size MeasureText (System.Drawing.IDeviceContext dc, string? text, System.Drawing.Font? font);
static member MeasureText : System.Drawing.IDeviceContext * string * System.Drawing.Font -> System.Drawing.Size
Public Shared Function MeasureText (dc As IDeviceContext, text As String, font As Font) As Size

매개 변수

dc
IDeviceContext

텍스트를 측정할 디바이스 컨텍스트입니다.

text
String

측정할 텍스트입니다.

font
Font

측정한 텍스트에 적용할 Font입니다.

반환

지정된 디바이스 컨텍스트에서 지정된 text를 사용하여 한 줄에 그린 fontSize(픽셀)입니다.

예제

다음 코드 예제 중 하나를 사용 하는 방법에 설명 합니다 MeasureText 메서드. 이 예제를 실행 하려면 호출을 Windows Form에 코드를 붙여넣은 DrawALineOfText 폼의 Paint 이벤트 처리기를 전달 e 으로 PaintEventArgs입니다.

private static void DrawALineOfText(PaintEventArgs e)
{
    // Declare strings to render on the form.
    string[] stringsToPaint = { "Tail", "Spin", " Toys" };

    // Declare fonts for rendering the strings.
    Font[] fonts = { new Font("Arial", 14, FontStyle.Regular), 
        new Font("Arial", 14, FontStyle.Italic), 
        new Font("Arial", 14, FontStyle.Regular) };

    Point startPoint = new Point(10, 10);

    // Set TextFormatFlags to no padding so strings are drawn together.
    TextFormatFlags flags = TextFormatFlags.NoPadding;

    // Declare a proposed size with dimensions set to the maximum integer value.
    Size proposedSize = new Size(int.MaxValue, int.MaxValue);

    // Measure each string with its font and NoPadding value and 
    // draw it to the form.
    for (int i = 0; i < stringsToPaint.Length; i++)
    {
        Size size = TextRenderer.MeasureText(e.Graphics, stringsToPaint[i], 
            fonts[i], proposedSize, flags);
        Rectangle rect = new Rectangle(startPoint, size);
        TextRenderer.DrawText(e.Graphics, stringsToPaint[i], fonts[i],
            startPoint, Color.Black, flags);
        startPoint.X += size.Width;
    }
}
Private Sub DrawALineOfText(ByVal e As PaintEventArgs)
    ' Declare strings to render on the form.
    Dim stringsToPaint() As String = {"Tail", "Spin", " Toys"}

    ' Declare fonts for rendering the strings.
    Dim fonts() As Font = {New Font("Arial", 14, FontStyle.Regular), _
        New Font("Arial", 14, FontStyle.Italic), _
        New Font("Arial", 14, FontStyle.Regular)}

    Dim startPoint As New Point(10, 10)

    ' Set TextFormatFlags to no padding so strings are drawn together.
    Dim flags As TextFormatFlags = TextFormatFlags.NoPadding

    ' Declare a proposed size with dimensions set to the maximum integer value.
    Dim proposedSize As Size = New Size(Integer.MaxValue, Integer.MaxValue)

    ' Measure each string with its font and NoPadding value and draw it to the form.
    For i As Integer = 0 To stringsToPaint.Length - 1
        Dim size As Size = TextRenderer.MeasureText(e.Graphics, _
            stringsToPaint(i), fonts(i), proposedSize, flags)
        Dim rect As Rectangle = New Rectangle(startPoint, size)
        TextRenderer.DrawText(e.Graphics, stringsToPaint(i), fonts(i), _
            startPoint, Color.Black, flags)
        startPoint.X += size.Width
    Next
End Sub

설명

MeasureText 메서드에 한 줄 텍스트를 그리는 필요 합니다.

적용 대상

MeasureText(String, Font)

지정된 글꼴을 사용하여 그릴 때 지정된 텍스트의 크기(픽셀)를 제공합니다.

public:
 static System::Drawing::Size MeasureText(System::String ^ text, System::Drawing::Font ^ font);
public static System.Drawing.Size MeasureText (string text, System.Drawing.Font font);
public static System.Drawing.Size MeasureText (string? text, System.Drawing.Font? font);
static member MeasureText : string * System.Drawing.Font -> System.Drawing.Size
Public Shared Function MeasureText (text As String, font As Font) As Size

매개 변수

text
String

측정할 텍스트입니다.

font
Font

측정한 텍스트에 적용할 Font입니다.

반환

지정된 text를 사용하여 한 줄에 그린 fontSize(픽셀)입니다. DrawText(IDeviceContext, String, Font, Rectangle, Color, TextFormatFlags) 매개 변수를 사용하는 TextFormatFlags 오버로드 중 하나를 사용하여 텍스트를 그리는 방법을 조작할 수 있습니다. 예를 들어, TextRenderer의 기본 동작은 걸친 모양의 문자를 표시하기 위해 그린 텍스트의 경계 사각형에 여백을 추가하는 것입니다. 이러한 추가 공간 없이 한 줄의 텍스트를 그려야 하는 경우 DrawText(IDeviceContext, String, Font, Point, Color)MeasureText(IDeviceContext, String, Font) 매개 변수를 사용하는 SizeTextFormatFlags의 버전을 사용해야 합니다. 예제를 보려면 MeasureText(IDeviceContext, String, Font, Size, TextFormatFlags)를 참조하세요.

예제

다음 코드 예제에서는 MeasureText 메서드를 사용하는 방법을 보여 줍니다. 이 예제를 실행 하려면 호출을 Windows Form에 코드를 붙여넣은 MeasureText1 폼의 Paint 이벤트 처리기를 전달 e 으로 PaintEventArgs입니다.

private void MeasureText1(PaintEventArgs e)
{
    String text1 = "Measure this text";
    Font arialBold = new Font("Arial", 12.0F);
    Size textSize = TextRenderer.MeasureText(text1, arialBold);
    TextRenderer.DrawText(e.Graphics, text1, arialBold, 
        new Rectangle(new Point(10, 10), textSize), Color.Red);  
}
Private Sub MeasureText1(ByVal e As PaintEventArgs)
    Dim text1 As String = "Measure this text"
    Dim arialBold As New Font("Arial", 12.0F)
    Dim textSize As Size = TextRenderer.MeasureText(text1, arialBold)
    TextRenderer.DrawText(e.Graphics, text1, arialBold, _
        New Rectangle(New Point(10, 10), textSize), Color.Red)

End Sub

설명

MeasureText 메서드에 한 줄 텍스트를 그리는 필요 합니다.

적용 대상

MeasureText(ReadOnlySpan<Char>, Font)

지정된 글꼴을 사용하여 그릴 때 지정된 텍스트의 크기(픽셀)를 제공합니다.

public:
 static System::Drawing::Size MeasureText(ReadOnlySpan<char> text, System::Drawing::Font ^ font);
public static System.Drawing.Size MeasureText (ReadOnlySpan<char> text, System.Drawing.Font? font);
static member MeasureText : ReadOnlySpan<char> * System.Drawing.Font -> System.Drawing.Size
Public Shared Function MeasureText (text As ReadOnlySpan(Of Char), font As Font) As Size

매개 변수

text
ReadOnlySpan<Char>

측정할 텍스트입니다.

font
Font

측정한 텍스트에 적용할 Font입니다.

반환

지정된 글꼴을 사용하여 한 줄에 그린 텍스트의 Size(픽셀)입니다. DrawText(IDeviceContext, ReadOnlySpan<Char>, Font, Rectangle, Color, TextFormatFlags) 매개 변수를 사용하는 TextFormatFlags 오버로드 중 하나를 사용하여 텍스트를 그리는 방법을 조작할 수 있습니다. 예를 들어, TextRenderer의 기본 동작은 걸친 모양의 문자를 표시하기 위해 그린 텍스트의 경계 사각형에 여백을 추가하는 것입니다. 이러한 추가 공간 없이 한 줄의 텍스트를 그려야 하는 경우 크기와 TextFormatFlags 매개 변수를 사용하는 DrawText(IDeviceContext, ReadOnlySpan<Char>, Font, Point, Color)MeasureText(IDeviceContext, ReadOnlySpan<Char>, Font) 버전을 사용해야 합니다. 예제를 보려면 MeasureText(IDeviceContext, String, Font, Size, TextFormatFlags)를 참조하세요.

적용 대상

MeasureText(IDeviceContext, ReadOnlySpan<Char>, Font, Size, TextFormatFlags)

텍스트의 초기 경계 사각형을 만들 지정된 크기를 사용하여 지정된 디바이스 컨텍스트, 글꼴 및 서식 명령으로 그릴 때 지정된 텍스트의 크기(픽셀)를 제공합니다.

public:
 static System::Drawing::Size MeasureText(System::Drawing::IDeviceContext ^ dc, ReadOnlySpan<char> text, System::Drawing::Font ^ font, System::Drawing::Size proposedSize, System::Windows::Forms::TextFormatFlags flags);
public static System.Drawing.Size MeasureText (System.Drawing.IDeviceContext dc, ReadOnlySpan<char> text, System.Drawing.Font? font, System.Drawing.Size proposedSize, System.Windows.Forms.TextFormatFlags flags);
static member MeasureText : System.Drawing.IDeviceContext * ReadOnlySpan<char> * System.Drawing.Font * System.Drawing.Size * System.Windows.Forms.TextFormatFlags -> System.Drawing.Size
Public Shared Function MeasureText (dc As IDeviceContext, text As ReadOnlySpan(Of Char), font As Font, proposedSize As Size, flags As TextFormatFlags) As Size

매개 변수

dc
IDeviceContext

텍스트를 측정할 디바이스 컨텍스트입니다.

text
ReadOnlySpan<Char>

측정할 텍스트입니다.

font
Font

측정한 텍스트에 적용할 Font입니다.

proposedSize
Size

초기 경계 사각형의 Size입니다.

flags
TextFormatFlags

측정한 텍스트에 적용할 서식 명령입니다.

반환

지정된 text와 형식을 사용하여 그린 fontSize(픽셀)입니다.

예외

dcnull입니다.

적용 대상

MeasureText(ReadOnlySpan<Char>, Font, Size)

초기 경계 사각형을 만들 지정된 크기를 사용하여 지정된 글꼴로 그릴 때 지정된 텍스트의 크기(픽셀)를 제공합니다.

public:
 static System::Drawing::Size MeasureText(ReadOnlySpan<char> text, System::Drawing::Font ^ font, System::Drawing::Size proposedSize);
public static System.Drawing.Size MeasureText (ReadOnlySpan<char> text, System.Drawing.Font? font, System.Drawing.Size proposedSize);
static member MeasureText : ReadOnlySpan<char> * System.Drawing.Font * System.Drawing.Size -> System.Drawing.Size
Public Shared Function MeasureText (text As ReadOnlySpan(Of Char), font As Font, proposedSize As Size) As Size

매개 변수

text
ReadOnlySpan<Char>

측정할 텍스트입니다.

font
Font

측정한 텍스트에 적용할 Font입니다.

proposedSize
Size

초기 경계 사각형의 Size입니다.

반환

지정된 text를 사용하여 그린 fontSize(픽셀)입니다.

적용 대상

MeasureText(IDeviceContext, String, Font, Size, TextFormatFlags)

텍스트의 초기 경계 사각형을 만들 지정된 크기를 사용하여 지정된 디바이스 컨텍스트, 글꼴 및 서식 명령으로 그릴 때 지정된 텍스트의 크기(픽셀)를 제공합니다.

public:
 static System::Drawing::Size MeasureText(System::Drawing::IDeviceContext ^ dc, System::String ^ text, System::Drawing::Font ^ font, System::Drawing::Size proposedSize, System::Windows::Forms::TextFormatFlags flags);
public static System.Drawing.Size MeasureText (System.Drawing.IDeviceContext dc, string text, System.Drawing.Font font, System.Drawing.Size proposedSize, System.Windows.Forms.TextFormatFlags flags);
public static System.Drawing.Size MeasureText (System.Drawing.IDeviceContext dc, string? text, System.Drawing.Font? font, System.Drawing.Size proposedSize, System.Windows.Forms.TextFormatFlags flags);
static member MeasureText : System.Drawing.IDeviceContext * string * System.Drawing.Font * System.Drawing.Size * System.Windows.Forms.TextFormatFlags -> System.Drawing.Size
Public Shared Function MeasureText (dc As IDeviceContext, text As String, font As Font, proposedSize As Size, flags As TextFormatFlags) As Size

매개 변수

dc
IDeviceContext

텍스트를 측정할 디바이스 컨텍스트입니다.

text
String

측정할 텍스트입니다.

font
Font

측정한 텍스트에 적용할 Font입니다.

proposedSize
Size

초기 경계 사각형의 Size입니다.

flags
TextFormatFlags

측정한 텍스트에 적용할 서식 명령입니다.

반환

지정된 text와 형식을 사용하여 그린 fontSize(픽셀)입니다.

예외

dc이(가) null인 경우

예제

다음 예제에서는 사용 하는 방법에 설명 합니다 MeasureTextDrawText 다른 글꼴 스타일에서을 한 줄 텍스트를 그리는 방법입니다. Windows Form 및 호출에서 다음 코드를 붙여넣고가이 예제를 실행 하려면 DrawALineOfText 폼의 Paint 이벤트 처리기를 전달 e 으로 PaintEventArgs입니다.

private static void DrawALineOfText(PaintEventArgs e)
{
    // Declare strings to render on the form.
    string[] stringsToPaint = { "Tail", "Spin", " Toys" };

    // Declare fonts for rendering the strings.
    Font[] fonts = { new Font("Arial", 14, FontStyle.Regular), 
        new Font("Arial", 14, FontStyle.Italic), 
        new Font("Arial", 14, FontStyle.Regular) };

    Point startPoint = new Point(10, 10);

    // Set TextFormatFlags to no padding so strings are drawn together.
    TextFormatFlags flags = TextFormatFlags.NoPadding;

    // Declare a proposed size with dimensions set to the maximum integer value.
    Size proposedSize = new Size(int.MaxValue, int.MaxValue);

    // Measure each string with its font and NoPadding value and 
    // draw it to the form.
    for (int i = 0; i < stringsToPaint.Length; i++)
    {
        Size size = TextRenderer.MeasureText(e.Graphics, stringsToPaint[i], 
            fonts[i], proposedSize, flags);
        Rectangle rect = new Rectangle(startPoint, size);
        TextRenderer.DrawText(e.Graphics, stringsToPaint[i], fonts[i],
            startPoint, Color.Black, flags);
        startPoint.X += size.Width;
    }
}
Private Sub DrawALineOfText(ByVal e As PaintEventArgs)
    ' Declare strings to render on the form.
    Dim stringsToPaint() As String = {"Tail", "Spin", " Toys"}

    ' Declare fonts for rendering the strings.
    Dim fonts() As Font = {New Font("Arial", 14, FontStyle.Regular), _
        New Font("Arial", 14, FontStyle.Italic), _
        New Font("Arial", 14, FontStyle.Regular)}

    Dim startPoint As New Point(10, 10)

    ' Set TextFormatFlags to no padding so strings are drawn together.
    Dim flags As TextFormatFlags = TextFormatFlags.NoPadding

    ' Declare a proposed size with dimensions set to the maximum integer value.
    Dim proposedSize As Size = New Size(Integer.MaxValue, Integer.MaxValue)

    ' Measure each string with its font and NoPadding value and draw it to the form.
    For i As Integer = 0 To stringsToPaint.Length - 1
        Dim size As Size = TextRenderer.MeasureText(e.Graphics, _
            stringsToPaint(i), fonts(i), proposedSize, flags)
        Dim rect As Rectangle = New Rectangle(startPoint, size)
        TextRenderer.DrawText(e.Graphics, stringsToPaint(i), fonts(i), _
            startPoint, Color.Black, flags)
        startPoint.X += size.Width
    Next
End Sub

설명

합니다 MeasureText 메서드를 proposedSizeflags 텍스트 크기를 결정할 때 높이 너비의 관계를 나타내기 위해 매개 변수입니다. 측정 하는 경우 텍스트 줄의 경우는 proposedSize 매개 변수를 나타냅니다는 Size 보다 큰 높이 차원 Int32.MaxValue, 반환 된 Size 텍스트의 실제 높이 맞게 조정 됩니다.

DrawText 매개 변수를 사용하는 TextFormatFlags 오버로드 중 하나를 사용하여 텍스트를 그리는 방법을 조작할 수 있습니다. 예를 들어, TextRenderer의 기본 동작은 걸친 모양의 문자를 표시하기 위해 그린 텍스트의 경계 사각형에 여백을 추가하는 것입니다. 이러한 추가 공간 없이 텍스트 줄을 그릴 경우의 버전을 사용 DrawText 하 고 MeasureText 사용 하는 SizeTextFormatFlags 예제에 표시 된 대로 매개 변수입니다.

적용 대상