DataGridViewRowPrePaintEventArgs.InheritedRowStyle Vlastnost

Definice

Získá styl buňky použitý na řádek.

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

Hodnota vlastnosti

A DataGridViewCellStyle obsahující styl buňky, který je aktuálně použitý na řádek.

Příklady

Následující příklad kódu ukazuje, jak pomocí InheritedRowStyle vlastnosti vykreslit vlastní pozadí pro vybraný řádek. Proměnná e, je typu DataGridViewRowPrePaintEventArgs. Tento příklad kódu je součástí většího příkladu v části Postupy: Přizpůsobení vzhledu řádků v ovládacím prvku model Windows Forms DataGridView.

// Determine whether the cell should be painted
// with the custom selection background.
if ((e.State & DataGridViewElementStates.Selected) ==
            DataGridViewElementStates.Selected)
{
    // Calculate the bounds of the row.
    Rectangle rowBounds = new Rectangle(
        this.dataGridView1.RowHeadersWidth, e.RowBounds.Top,
        this.dataGridView1.Columns.GetColumnsWidth(
            DataGridViewElementStates.Visible) -
        this.dataGridView1.HorizontalScrollingOffset + 1,
        e.RowBounds.Height);

    // Paint the custom selection background.
    using (Brush backbrush =
        new System.Drawing.Drawing2D.LinearGradientBrush(rowBounds,
            this.dataGridView1.DefaultCellStyle.SelectionBackColor,
            e.InheritedRowStyle.ForeColor,
            System.Drawing.Drawing2D.LinearGradientMode.Horizontal))
    {
        e.Graphics.FillRectangle(backbrush, rowBounds);
    }
}
' Determine whether the cell should be painted with the 
' custom selection background.
If (e.State And DataGridViewElementStates.Selected) = _
    DataGridViewElementStates.Selected Then

    ' Calculate the bounds of the row.
    Dim rowBounds As New Rectangle( _
        Me.dataGridView1.RowHeadersWidth, e.RowBounds.Top, _
        Me.dataGridView1.Columns.GetColumnsWidth( _
        DataGridViewElementStates.Visible) - _
        Me.dataGridView1.HorizontalScrollingOffset + 1, _
        e.RowBounds.Height)

    ' Paint the custom selection background.
    Dim backbrush As New _
        System.Drawing.Drawing2D.LinearGradientBrush(rowBounds, _
        Me.dataGridView1.DefaultCellStyle.SelectionBackColor, _
        e.InheritedRowStyle.ForeColor, _
        System.Drawing.Drawing2D.LinearGradientMode.Horizontal)
    Try
        e.Graphics.FillRectangle(backbrush, rowBounds)
    Finally
        backbrush.Dispose()
    End Try
End If

Poznámky

Vlastnost InheritedRowStyle obsahuje stejné hodnoty jako vlastnost řádku InheritedStyle . Přímý přístup k objektu DataGridViewRow v objektu může mít vliv na DataGridView výkon. Použijte InheritedRowStyle v události RowPrePaint , abyste zabránili zrušení sdílení řádku a zachovali optimální výkon.

Vlastnost InheritedRowStyle je jen pro čtení. I když můžete nastavit vlastnosti načtené DataGridViewCellStyle prostřednictvím InheritedRowStyle vlastnosti, nová nastavení nebudou mít žádný vliv.

Platí pro

Viz také