Winform datagridview画斜线表头

      

  ///


        /// 画斜线表头
        ///

        ///
        ///
        ///
        ///
        void PaintLine(DataGridViewCellPaintingEventArgs e, string type, string name1, string name2)
        {          
            if ((type == "1" && e.ColumnIndex == 1 && e.RowIndex == -1) || (e.ColumnIndex == 0 && e.RowIndex == -1 && type == "2"))
            {
                Graphics gp = e.Graphics;
                Rectangle rec = e.CellBounds;
                Brush gridBrush = new SolidBrush(Color.FromArgb(208, 215, 229));
                Pen gridLinePen = new Pen(gridBrush);
                gp.DrawLine(gridLinePen, new Point(rec.X, rec.Y), new Point(rec.X + rec.Width, rec.Y + rec.Height));
              
                float x = 55;
                if (type == "1")
                    x = x + 30;
                gp.DrawString(name1, e.CellStyle.Font, Brushes.Black, new PointF(rec.X + 12, rec.Y + 22));
                gp.DrawString(name2, e.CellStyle.Font, Brushes.Black, new PointF(rec.X + x, rec.Y + 5));
            }

        }

 

 

你可能感兴趣的:(winform,string,float)