public void Paint(MyDGV0427 dgv, PaintEventArgs e, Point location) { //区域填充 Rectangle r1 = new Rectangle() { X = location.X + 1, Y = location.Y + 1, Width = Width - 2, Height = Height - 2, }; e.Graphics.FillRectangle(new SolidBrush(dgv.ColumnHeadersDefaultCellStyle.BackColor), r1); //文字 StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; e.Graphics.DrawString(ColumnName, dgv.ColumnHeadersDefaultCellStyle.Font, new SolidBrush(dgv.ColumnHeadersDefaultCellStyle.ForeColor), r1, format); //递归处理子节点 if (!IsLeaf()) { int width = 0; foreach (var SubNode in SubNodes) { SubNode.Paint(dgv, e, new Point(location.X + width, location.Y + Height)); width += SubNode.Width; } } }
public void Paint(MyDGV0427 dgv, DataGridViewCellPaintingEventArgs e, Point location) { //区域填充 Rectangle r1 = new Rectangle() { X = location.X + 1, Y = location.Y + 1, Width = Width - 2, Height = Height - 2, }; e.Graphics.FillRectangle(new SolidBrush(dgv.ColumnHeadersDefaultCellStyle.BackColor), r1); SolidBrush gridBrush = new SolidBrush(dgv.GridColor); Pen gridLinePen = new Pen(gridBrush); //描边-底线 e.Graphics.DrawLine(gridLinePen , r1.Left , r1.Bottom , r1.Right , r1.Bottom); //描边-右端线 e.Graphics.DrawLine(gridLinePen , r1.Right , r1.Top , r1.Right , r1.Bottom); //文字 StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; e.Graphics.DrawString(HeaderText, dgv.ColumnHeadersDefaultCellStyle.Font, new SolidBrush(dgv.ColumnHeadersDefaultCellStyle.ForeColor), r1, format); //递归处理子节点 if (!IsLeaf()) { int width = 0; foreach (var SubNode in SubNodes) { SubNode.Paint(dgv, e, new Point(location.X + width, location.Y + Height)); width += SubNode.Width; } } }