search
尋找貓咪~QQ 地點 桃園市桃園區 Taoyuan , Taoyuan

C# datagridview 文字顏色 – jashliao部落格

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;



熱門推薦

本文由 jashliaoeuwordpress 提供 原文連結

寵物協尋 相信 終究能找到回家的路
寫了7763篇文章,獲得2次喜歡
留言回覆
回覆
精彩推薦