DataGridViewRowPrePaintEventArgs.InheritedRowStyle Propriedade
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Aplica-se o estilo de célula à linha.
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
Valor de Propriedade
A DataGridViewCellStyle que contém o estilo de célula atualmente aplicado à linha.
Exemplos
O exemplo de código seguinte demonstra como usar a InheritedRowStyle propriedade para pintar um fundo personalizado para a linha selecionada. A variável, e, é do tipo DataGridViewRowPrePaintEventArgs. Este exemplo de código faz parte de um exemplo maior fornecido em Como Personalizar: A Aparência das Linhas no Controlo 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
Observações
A InheritedRowStyle propriedade contém os mesmos valores que a propriedade da InheritedStyle linha. Aceder diretamente a um DataGridViewRow no DataGridView pode afetar o desempenho. Use InheritedRowStyle no RowPrePaint evento para evitar deixar de partilhar a linha e manter o desempenho ideal.
A InheritedRowStyle propriedade é apenas de leitura. Embora possas definir as propriedades do DataGridViewCellStyle recuperado através da InheritedRowStyle propriedade, as novas definições não terão qualquer efeito.