DrawListViewSubItemEventArgs.DrawText 메서드

정의

현재 전경색과 기본 서식을 사용하여 ListViewItem.ListViewSubItem의 텍스트를 그립니다.

오버로드

DrawText()

현재 전경색을 사용하여 ListViewItem.ListViewSubItem의 텍스트를 그립니다.

DrawText(TextFormatFlags)

현재 전경색을 사용하여 ListViewItem.ListViewSubItem의 텍스트를 그리고 지정된 TextFormatFlags 값을 사용하여 서식을 지정합니다.

DrawText()

현재 전경색을 사용하여 ListViewItem.ListViewSubItem의 텍스트를 그립니다.

public:
 void DrawText();
public void DrawText ();
member this.DrawText : unit -> unit
Public Sub DrawText ()

설명

현재 값을 사용 하 여 하위 항목 텍스트를 그리려면이 메서드를 사용 합니다 ListViewItem.ListViewSubItem.ForeColorListViewItem.ListViewSubItem.Font 속성입니다. 지정한 영역 내에서 텍스트를 그리는 Bounds 속성입니다.

참고

UseItemStyleForSubItems 부모 ListViewItem 로 설정 되어야 합니다 false 방지 하기 위해 합니다 ListViewItem.ForeColorListViewItem.Font 하위 항목 값을 재정의에서 부모 항목의 값입니다.

추가 정보

적용 대상

DrawText(TextFormatFlags)

현재 전경색을 사용하여 ListViewItem.ListViewSubItem의 텍스트를 그리고 지정된 TextFormatFlags 값을 사용하여 서식을 지정합니다.

public:
 void DrawText(System::Windows::Forms::TextFormatFlags flags);
public void DrawText (System.Windows.Forms.TextFormatFlags flags);
member this.DrawText : System.Windows.Forms.TextFormatFlags -> unit
Public Sub DrawText (flags As TextFormatFlags)

매개 변수

flags
TextFormatFlags

TextFormatFlags 값의 비트 조합입니다.

예제

다음 코드 예제를 사용 하는 방법에 설명 합니다 DrawText 에 대 한 사용자 지정 그리기를 제공 하는 애플리케이션에서 메서드를 ListView 컨트롤입니다. 예에 대 한 처리기를 ListView.DrawSubItem 이벤트 하위 항목 텍스트 값 및 텍스트와 음수 값이 있는 하위 항목의 배경을 그립니다.

전체 예제를 참조 하세요.를 DrawListViewSubItemEventArgs 개요 항목을 참조 합니다.

// Draws subitem text and applies content-based formatting.
private void listView1_DrawSubItem(object sender,
    DrawListViewSubItemEventArgs e)
{
    TextFormatFlags flags = TextFormatFlags.Left;

    using (StringFormat sf = new StringFormat())
    {
        // Store the column text alignment, letting it default
        // to Left if it has not been set to Center or Right.
        switch (e.Header.TextAlign)
        {
            case HorizontalAlignment.Center:
                sf.Alignment = StringAlignment.Center;
                flags = TextFormatFlags.HorizontalCenter;
                break;
            case HorizontalAlignment.Right:
                sf.Alignment = StringAlignment.Far;
                flags = TextFormatFlags.Right;
                break;
        }

        // Draw the text and background for a subitem with a 
        // negative value. 
        double subItemValue;
        if (e.ColumnIndex > 0 && Double.TryParse(
            e.SubItem.Text, NumberStyles.Currency,
            NumberFormatInfo.CurrentInfo, out subItemValue) &&
            subItemValue < 0)
        {
            // Unless the item is selected, draw the standard 
            // background to make it stand out from the gradient.
            if ((e.ItemState & ListViewItemStates.Selected) == 0)
            {
                e.DrawBackground();
            }

            // Draw the subitem text in red to highlight it. 
            e.Graphics.DrawString(e.SubItem.Text,
                listView1.Font, Brushes.Red, e.Bounds, sf);

            return;
        }

        // Draw normal text for a subitem with a nonnegative 
        // or nonnumerical value.
        e.DrawText(flags);
    }
}
' Draws subitem text and applies content-based formatting.
Private Sub listView1_DrawSubItem(ByVal sender As Object, _
    ByVal e As DrawListViewSubItemEventArgs) _
    Handles listView1.DrawSubItem

    Dim flags As TextFormatFlags = TextFormatFlags.Left

    Dim sf As New StringFormat()
    Try

        ' Store the column text alignment, letting it default
        ' to Left if it has not been set to Center or Right.
        Select Case e.Header.TextAlign
            Case HorizontalAlignment.Center
                sf.Alignment = StringAlignment.Center
                flags = TextFormatFlags.HorizontalCenter
            Case HorizontalAlignment.Right
                sf.Alignment = StringAlignment.Far
                flags = TextFormatFlags.Right
        End Select

        ' Draw the text and background for a subitem with a 
        ' negative value. 
        Dim subItemValue As Double
        If e.ColumnIndex > 0 AndAlso _
            Double.TryParse(e.SubItem.Text, NumberStyles.Currency, _
            NumberFormatInfo.CurrentInfo, subItemValue) AndAlso _
            subItemValue < 0 Then

            ' Unless the item is selected, draw the standard 
            ' background to make it stand out from the gradient.
            If (e.ItemState And ListViewItemStates.Selected) = 0 Then
                e.DrawBackground()
            End If

            ' Draw the subitem text in red to highlight it. 
            e.Graphics.DrawString(e.SubItem.Text, _
                Me.listView1.Font, Brushes.Red, e.Bounds, sf)

            Return

        End If

        ' Draw normal text for a subitem with a nonnegative 
        ' or nonnumerical value.
        e.DrawText(flags)

    Finally
        sf.Dispose()
    End Try

End Sub

설명

현재 값을 사용 하 여 하위 항목 텍스트를 그리려면이 메서드를 사용 합니다 ListViewItem.ListViewSubItem.ForeColorListViewItem.ListViewSubItem.Font 속성입니다. 지정한 영역 내에서 텍스트를 그리는 Bounds 속성입니다. 합니다 TextFormatFlags 에 지정 된 값을 flags 매개 변수를 사용 하면 노드 레이블 텍스트 맞춤 등의 서식 속성을 제공할 수 있습니다.

참고

UseItemStyleForSubItems 부모 ListViewItem 로 설정 되어야 합니다 false 방지 하기 위해 합니다 ListViewItem.ForeColorListViewItem.Font 하위 항목 값을 재정의에서 부모 항목의 값입니다.

추가 정보

적용 대상