//控件的行重绘事件 private void MasterControl_RowPostPaint(object obj_sender, DataGridViewRowPostPaintEventArgs e) { try { var sender = (DataGridView)obj_sender; //set childview control var rect = new Rectangle((int)(e.RowBounds.X + ((double)(rowDefaultHeight - 16) / 2)), (int)(e.RowBounds.Y + ((double)(rowDefaultHeight - 16) / 2)), 16, 16); if (collapseRow) { if (this.rowCurrent.Contains(e.RowIndex)) { #region 更改点开后背景色 刘金龙 var rect1 = new Rectangle(e.RowBounds.X, e.RowBounds.Y + rowDefaultHeight, e.RowBounds.Width, e.RowBounds.Height - rowDefaultHeight); using (Brush b = new SolidBrush(Color.FromArgb(164, 169, 143))) { e.Graphics.FillRectangle(b, rect1); } using (Pen p = new Pen(Color.GhostWhite)) { var iHalfWidth = (e.RowBounds.Left + sender.RowHeadersWidth) / 2; var oPointHLineStart = new Point(rect1.X + iHalfWidth, rect1.Y); var oPointHLineEnd = new Point(rect1.X + iHalfWidth, rect1.Y + rect1.Height / 2); e.Graphics.DrawLine(p, oPointHLineStart, oPointHLineEnd); //折叠线 e.Graphics.DrawLine(p, oPointHLineEnd, new Point(oPointHLineEnd.X + iHalfWidth, oPointHLineEnd.Y)); } #endregion sender.Rows[e.RowIndex].DividerHeight = sender.Rows[e.RowIndex].Height - rowDefaultHeight; e.Graphics.DrawImage(RowHeaderIconList.Images[(int)rowHeaderIcons.collapse], rect); childView.Location = new Point(e.RowBounds.Left + sender.RowHeadersWidth, e.RowBounds.Top + rowDefaultHeight + 5); childView.Width = e.RowBounds.Right - sender.RowHeadersWidth; childView.Height = System.Convert.ToInt32(sender.Rows[e.RowIndex].DividerHeight - 10); childView.Visible = true; } else { childView.Visible = false; e.Graphics.DrawImage(RowHeaderIconList.Images[(int)rowHeaderIcons.expand], rect); } collapseRow = false; } else { if (this.rowCurrent.Contains(e.RowIndex)) { #region 更改点开后背景色 刘金龙 var rect1 = new Rectangle(e.RowBounds.X, e.RowBounds.Y + rowDefaultHeight, e.RowBounds.Width, e.RowBounds.Height - rowDefaultHeight); using (Brush b = new SolidBrush(Color.FromArgb(164, 169, 143))) { e.Graphics.FillRectangle(b, rect1); } using (Pen p = new Pen(Color.GhostWhite)) { var iHalfWidth = (e.RowBounds.Left + sender.RowHeadersWidth) / 2; var oPointHLineStart = new Point(rect1.X + iHalfWidth, rect1.Y); var oPointHLineEnd = new Point(rect1.X + iHalfWidth, rect1.Y + rect1.Height / 2); e.Graphics.DrawLine(p, oPointHLineStart, oPointHLineEnd); //折叠线 e.Graphics.DrawLine(p, oPointHLineEnd, new Point(oPointHLineEnd.X + iHalfWidth, oPointHLineEnd.Y)); } #endregion sender.Rows[e.RowIndex].DividerHeight = sender.Rows[e.RowIndex].Height - rowDefaultHeight; e.Graphics.DrawImage(RowHeaderIconList.Images[(int)rowHeaderIcons.collapse], rect); childView.Location = new Point(e.RowBounds.Left + sender.RowHeadersWidth, e.RowBounds.Top + rowDefaultHeight + 5); childView.Width = e.RowBounds.Right - sender.RowHeadersWidth; childView.Height = System.Convert.ToInt32(sender.Rows[e.RowIndex].DividerHeight - 10); childView.Visible = true; } else { childView.Visible = false; e.Graphics.DrawImage(RowHeaderIconList.Images[(int)rowHeaderIcons.expand], rect); } } CellStyle.rowPostPaint_HeaderCount(sender, e); } catch { } }