系统默认表格

修改后的标题行

public partial class CC_DataGridView : DataGridView
{
public CC_DataGridView()
{
InitializeComponent();
this.AllowUserToAddRows = false;
this.AllowUserToDeleteRows = false;
this.AllowUserToResizeRows = true;
this.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
this.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
this.BackgroundColor = Color.FromArgb(9, 21, 61);//背景色
this.BorderStyle = BorderStyle.None;
this.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;
this.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
this.ColumnHeadersDefaultCellStyle.WrapMode = DataGridViewTriState.NotSet;
this.ColumnHeadersDefaultCellStyle.BackColor = Color.FromArgb(9, 51, 102);//列标题背景色
this.ColumnHeadersDefaultCellStyle.Font = Font;
this.ColumnHeadersDefaultCellStyle.ForeColor = Color.White;
this.ColumnHeadersHeight = 50;//列标题高度
this.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing;//控制列标题高度,在属性里设置
this.EnableHeadersVisualStyles = false;
this.GridColor = Color.FromArgb(3, 72, 149);//网格颜色
this.ReadOnly = true;
this.RowHeadersVisible = false;
this.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
this.RowsDefaultCellStyle.BackColor = Color.FromArgb(9, 21, 61);//行背景色
this.RowsDefaultCellStyle.ForeColor = Color.White;
this.RowsDefaultCellStyle.SelectionBackColor = Color.FromArgb(9, 21, 61);//选中行的颜色
this.RowTemplate.Height = 50;//行高
this.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
}
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
}
}

本文介绍了一个自定义的DataGridView控件实现,详细展示了如何修改默认的DataGridView样式,包括背景色、字体、边框、网格线、列标题样式等,以适应更个性化的设计需求。
5939

被折叠的 条评论
为什么被折叠?



