111,093
社区成员




int height = this.dataGridView1.Height;
int scrollbarheight = this.dataGridView1.Columns.GetColumnsWidth(DataGridViewElementStates.None) > this.dataGridView1.Width ? 16 : 0;//水平滚动条高
int rowheaderswidth = this.dataGridView1.RowHeadersVisible ? this.dataGridView1.RowHeadersWidth : 0;//行标题宽度
// int rowheaderswidth =40
int length = rowheaderswidth;
Panel panel = new Panel();
panel.Name = this.dataGridView1.Name;
panel.BackColor = Color.Red;
panel.Left = 1;
panel.Top = height - scrollbarheight - 23 - 1;
dataGridView1.Controls.Add(panel);
for (int i = 0; i < this.dataGridView1.Columns.Count; i++)
{
DataGridViewColumn column = this.dataGridView1.Columns[i];
if (column.Visible)
{
Label lblChild = new Label();
lblChild.Name = column.Name ;
lblChild.BackColor = Color.Yellow;
lblChild.AutoSize = true;
lblChild.Left = length + ((int)column.Width / 2) - 10 + 1;
length += column.Width;
// lblChild.Width = column.Width;
lblChild.Top = 3;
panel.Controls.Add(lblChild);
}
}