DataGridViewRowPrePaintEventArgs.InheritedRowStyle Свойство

Определение

Возвращает стиль ячейки, примененный к строке.

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

Значение свойства

Объект DataGridViewCellStyle, который содержит стиль ячейки, примененный в настоящее время к ячейке.

Примеры

В следующем примере кода показано, как использовать свойство для рисования InheritedRowStyle пользовательского фона для выбранной строки. Переменная eимеет тип DataGridViewRowPrePaintEventArgs. Этот пример кода является частью более крупного примера, приведенного в разделе How to: Customize the Appearance of Rows in the Windows Forms DataGridView Control.

// 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

Комментарии

Свойство InheritedRowStyle содержит те же значения, что и свойство строки InheritedStyle . Прямой доступ к в DataGridViewRow может DataGridView повлиять на производительность. Используйте InheritedRowStyle в событии RowPrePaint , чтобы избежать отмены совместного использования строки и поддерживать оптимальную производительность.

Свойство InheritedRowStyle доступно только для чтения. Хотя можно задать свойства объекта , DataGridViewCellStyle полученного с помощью InheritedRowStyle свойства , новые параметры не будут иметь никакого эффекта.

Применяется к

См. также раздел