共用方式為


DrawListViewColumnHeaderEventArgs.Header 屬性

定義

取得 ColumnHeader,表示要繪製的資料行行首。

public:
 property System::Windows::Forms::ColumnHeader ^ Header { System::Windows::Forms::ColumnHeader ^ get(); };
public System.Windows.Forms.ColumnHeader Header { get; }
public System.Windows.Forms.ColumnHeader? Header { get; }
member this.Header : System.Windows.Forms.ColumnHeader
Public ReadOnly Property Header As ColumnHeader

屬性值

ColumnHeader,表示資料行行首。

範例

下列程式碼範例示範如何在應用程式中使用 Header 屬性,以提供控制項的自訂繪圖 ListView

如需完整的範例,請參閱 DrawListViewColumnHeaderEventArgs 概觀參考主題。

// Draws column headers.
private void listView1_DrawColumnHeader(object sender,
    DrawListViewColumnHeaderEventArgs e)
{
    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;
                break;
            case HorizontalAlignment.Right:
                sf.Alignment = StringAlignment.Far;
                break;
        }

        // Draw the standard header background.
        e.DrawBackground();

        // Draw the header text.
        using (Font headerFont =
                    new Font("Helvetica", 10, FontStyle.Bold))
        {
            e.Graphics.DrawString(e.Header.Text, headerFont,
                Brushes.Black, e.Bounds, sf);
        }
    }
    return;
}
' Draws column headers.
Private Sub listView1_DrawColumnHeader(ByVal sender As Object, _
    ByVal e As DrawListViewColumnHeaderEventArgs) _
    Handles listView1.DrawColumnHeader

    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
            Case HorizontalAlignment.Right
                sf.Alignment = StringAlignment.Far
        End Select

        ' Draw the standard header background.
        e.DrawBackground()

        ' Draw the header text.
        Dim headerFont As New Font("Helvetica", 10, FontStyle.Bold)
        Try
            e.Graphics.DrawString(e.Header.Text, headerFont, _
                Brushes.Black, e.Bounds, sf)
        Finally
            headerFont.Dispose()
        End Try

    Finally
        sf.Dispose()
    End Try

End Sub

備註

當 屬性未提供足夠的資訊以符合您的需求時, State 這個屬性就很有用。 屬性 State 只提供基本狀態資訊,例如,用來判斷滑鼠是否位於資料行標頭上。 另一方面,屬性 Header 可讓您存取代表標頭之 的所有成員 ColumnHeader

適用於

另請參閱