DataGridViewCheckBoxColumn.FlatStyle 属性

定义

获取或设置复选框单元格的平面样式外观。

public:
 property System::Windows::Forms::FlatStyle FlatStyle { System::Windows::Forms::FlatStyle get(); void set(System::Windows::Forms::FlatStyle value); };
public System.Windows.Forms.FlatStyle FlatStyle { get; set; }
member this.FlatStyle : System.Windows.Forms.FlatStyle with get, set
Public Property FlatStyle As FlatStyle

属性值

FlatStyle

指示列中单元格外观的 FlatStyle 值。 默认值为 Standard

例外

CellTemplate 属性的值为 null

示例

下面的代码示例演示如何使用一个 DataGridViewCheckBoxColumn 标记哪些员工外出。 此示例是类概述主题中可用的较大示例的 DataGridViewComboBoxColumn 一部分。

private:
    void AddOutOfOfficeColumn()
    {
        DataGridViewCheckBoxColumn^ column = gcnew DataGridViewCheckBoxColumn();
        {
            column->HeaderText = ColumnName::OutOfOffice.ToString();
            column->Name = ColumnName::OutOfOffice.ToString();
            column->AutoSizeMode = 
                DataGridViewAutoSizeColumnMode::DisplayedCells;
            column->FlatStyle = FlatStyle::Standard;
            column->ThreeState = true;
            column->CellTemplate = gcnew DataGridViewCheckBoxCell();
            column->CellTemplate->Style->BackColor = Color::Beige;
        }

        DataGridView1->Columns->Insert(0, column);
    }
private void AddOutOfOfficeColumn()
{
    DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn();
    {
        column.HeaderText = ColumnName.OutOfOffice.ToString();
        column.Name = ColumnName.OutOfOffice.ToString();
        column.AutoSizeMode = 
            DataGridViewAutoSizeColumnMode.DisplayedCells;
        column.FlatStyle = FlatStyle.Standard;
        column.ThreeState = true;
        column.CellTemplate = new DataGridViewCheckBoxCell();
        column.CellTemplate.Style.BackColor = Color.Beige;
    }

    DataGridView1.Columns.Insert(0, column);
}
Private Sub AddOutOfOfficeColumn()
    Dim column As New DataGridViewCheckBoxColumn()
    With column
        .HeaderText = ColumnName.OutOfOffice.ToString()
        .Name = ColumnName.OutOfOffice.ToString()
        .AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells
        .FlatStyle = FlatStyle.Standard
        .CellTemplate = New DataGridViewCheckBoxCell()
        .CellTemplate.Style.BackColor = Color.Beige
    End With

    DataGridView1.Columns.Insert(0, column)
End Sub

注解

若要使用视觉样式显示复选框单元格,请将此属性设置为 System 之前的方法并调用 Application.EnableVisualStyles 该方法 Application.Run

获取或设置此属性获取或设置 FlatStyle 属性返回 CellTemplate 的单元格对象的属性。 设置此属性还会设置 FlatStyle 列中每个单元格的属性,并刷新列显示。 若要替代单个单元格的指定值,请设置列值后设置单元格值。

适用于

另请参阅