自定义控件系列<第二篇>--多维表头

本文介绍了如何创建和使用自定义控件来实现第二种多维表头的功能。通过提供的代码示例,展示了在窗体中调用此控件的方法,强调了积累在编程中的重要性。
摘要由CSDN通过智能技术生成

第二种多维表头

这里写图片描述

自定义控件代码

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 ==
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值