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.Font プロパティの現在の値を使用してサブ項目テキストを描画するには、このメソッドをListViewItem.ListViewSubItem.ForeColor使用します。 テキストは、 プロパティで指定された領域内に Bounds 描画されます。

注意

UseItemStyleForSubItemsListViewItemアイテムの と ListViewItem.Font の値がサブ項目の値をオーバーライドしないようにListViewItem.ForeColorするには、親の プロパティを に設定falseする必要があります。

こちらもご覧ください

適用対象

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.Font プロパティの現在の値を使用してサブ項目テキストを描画するには、このメソッドをListViewItem.ListViewSubItem.ForeColor使用します。 テキストは、 プロパティで指定された領域内に Bounds 描画されます。 TextFormatFlagsパラメーターで指定した値をflags使用すると、テキストの配置など、ノード ラベルの書式設定プロパティを指定できます。

注意

UseItemStyleForSubItemsListViewItemアイテムの と ListViewItem.Font の値がサブ項目の値をオーバーライドしないようにListViewItem.ForeColorするには、親の プロパティを に設定falseする必要があります。

こちらもご覧ください

適用対象