DataGridViewRowPostPaintEventArgs.InheritedRowStyle 属性

定义

获取应用于当前 DataGridViewRow 的单元格样式。Gets the cell style applied to the current DataGridViewRow.

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 的单元格样式的 DataGridViewRowA DataGridViewCellStyle that contains the cell style applied to the current DataGridViewRow.

示例

下面的代码示例演示如何使用InheritedRowStyle来确定用于绘制内容的颜色。The following code example demonstrates how to use the InheritedRowStyle to determine the color to use to draw the content. 变量e的类型DataGridViewRowPostPaintEventArgs为。The variable, e, is of type DataGridViewRowPostPaintEventArgs. 此代码示例摘自了如何:自定义 Windows 窗体 DataGridView 控件中的行的外观。This code example is part of a larger example provided in How to: Customize the Appearance of Rows in the Windows Forms DataGridView Control.

// Determine the foreground color.
if ((e.State & DataGridViewElementStates.Selected) ==
    DataGridViewElementStates.Selected)
{
    forebrush = new SolidBrush(e.InheritedRowStyle.SelectionForeColor);
}
else
{
    forebrush = new SolidBrush(e.InheritedRowStyle.ForeColor);
}
' Determine the foreground color.
If (e.State And DataGridViewElementStates.Selected) = _
    DataGridViewElementStates.Selected Then

    forebrush = New SolidBrush(e.InheritedRowStyle.SelectionForeColor)
Else
    forebrush = New SolidBrush(e.InheritedRowStyle.ForeColor)
End If

注解

属性包含的值与当前行的InheritedStyle属性相同。 InheritedRowStyleThe InheritedRowStyle property contains the same values as the current row's InheritedStyle property. DataGridViewRow 直接DataGridView在中访问的可能会影响性能。Directly accessing a DataGridViewRow in the DataGridView can affect performance. 在事件中使用InheritedRowStyle, 以避免取消行的共享并保持最佳性能。RowPostPaintUse InheritedRowStyle in the RowPostPaint event to avoid unsharing the row and maintain optimal performance.

InheritedRowStyle 属性为只读。The InheritedRowStyle property is read-only. 尽管可以DataGridViewCellStyle InheritedRowStyle通过属性设置检索到的属性, 但新的设置将不起作用。Although you can set the properties of the DataGridViewCellStyle retrieved through the InheritedRowStyle property, the new settings will have no effect.

适用于

另请参阅