C# datagridview 文字顏色

C# datagridview 文字顏色

C# datagridview 文字顏色


資料來源: https://docs.microsoft.com/zh-tw/dotnet/desktop/winforms/controls/how-to-set-font-and-color-styles-in-the-windows-forms-datagridview-control?view=netframeworkdesktop-4.8

https://bbs.csdn.net/topics/270042463


01.指定 DataGridView 儲存格所使用的字型

this.dataGridView1.DefaultCellStyle.Font = new Font("Tahoma", 15);


02.指定 DataGridView 儲存格的前景和背景色彩

this.dataGridView1.DefaultCellStyle.ForeColor = Color.Blue;
this.dataGridView1.DefaultCellStyle.BackColor = Color.Beige;

03.指定所選取 DataGridView 儲存格的前景和背景色彩

this.dataGridView1.DefaultCellStyle.SelectionForeColor = Color.Yellow;
this.dataGridView1.DefaultCellStyle.SelectionBackColor = Color.Black;


範例

private void SetFontAndColors()
{
    this.dataGridView1.DefaultCellStyle.Font = new Font("Tahoma", 15);
    this.dataGridView1.DefaultCellStyle.ForeColor = Color.Blue;
    this.dataGridView1.DefaultCellStyle.BackColor = Color.Beige;
    this.dataGridView1.DefaultCellStyle.SelectionForeColor = Color.Yellow;
    this.dataGridView1.DefaultCellStyle.SelectionBackColor = Color.Black;
}

dataGridView1.Rows[i].DefaultCellStyle.ForeColor = Color.Red;
dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Blue;

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *