DataGridViewRowPrePaintEventArgs.InheritedRowStyle Właściwość

Definicja

Pobiera styl komórki zastosowany do wiersza.

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

Wartość właściwości

Obiekt DataGridViewCellStyle , który zawiera styl komórki aktualnie zastosowany do wiersza.

Przykłady

W poniższym przykładzie kodu pokazano, jak za pomocą InheritedRowStyle właściwości malować niestandardowe tło dla wybranego wiersza. Zmienna , ejest typu DataGridViewRowPrePaintEventArgs. Ten przykład kodu jest częścią większego przykładu przedstawionego w temacie How to: Customize the Appearance of Rows in the Windows Forms DataGridView Control (Jak dostosować wygląd wierszy w kontrolce 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

Uwagi

Właściwość InheritedRowStyle zawiera te same wartości co właściwość wiersza InheritedStyle . Bezpośrednie uzyskiwanie dostępu do w DataGridViewRow obiekcie DataGridView może mieć wpływ na wydajność. Użyj InheritedRowStyle polecenia w zdarzeniu RowPrePaint , aby uniknąć udostępniania wiersza i zachować optymalną wydajność.

Właściwość InheritedRowStyle jest tylko do odczytu. Mimo że można ustawić właściwości DataGridViewCellStyle pobrane za pośrednictwem InheritedRowStyle właściwości, nowe ustawienia nie będą miały żadnego wpływu.

Dotyczy

Zobacz też