第二种多维表头
自定义控件代码
public partial class ZonCanKu : DataGridView
{
public ZonCanKu()
{
InitializeComponent();
}
public ZonCanKu(IContainer container)
{
container.Add(this);
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{//绘制界面
base.OnPaint(e);
}
protected override void OnCellPainting(DataGridViewCellPaintingEventArgs e)
{//绘制单元格
if (e.RowIndex == -1)
{
if (dic.ContainsKey(e.ColumnIndex))
{
//e.CellBounds当前单元格边界
Graphics g = e.Graphics;
//背景和边框
e.Paint(e.CellBounds, DataGridViewPaintParts.Background | DataGridViewPaintParts.Border);
//上半部分背景色
g.FillRectangle(new SolidBrush(e.CellStyle.BackColor), new Rectangle(e.CellBounds.X, e.CellBounds.Y, e.CellBounds.Width, e.CellBounds.Height / 2));
//画中线
g.DrawLine(new Pen(Color.Black), e.CellBounds.X, e.CellBounds.Y + (e.CellBounds.Height / 2), e.CellBounds.Right, e.CellBounds.Y + (e.CellBounds.Height / 2));
//画垂直线
if (e.ColumnIndex == 6 || e.ColumnIndex ==