先看看理想的效果.
http://hi.csdn.net/attachment/200912/24/148499_12616267360nta.jpg
重绘(问题一)
http://hi.csdn.net/attachment/200912/24/148499_1261626743i0gC.jpg
重绘(问题二)
http://hi.csdn.net/attachment/200912/24/148499_1261626746RUZY.jpg我把重绘放在了 dataGridView1_RowPostPaint 事件里面.
因为 dataGridView1_ColumnWidthChanged 的时候 ,我才能实现重绘合计行的竖线...问题来了:
当我拖动(变大) dataGridView1 高度的时候,如图2这个问题
当我拖动(变小) dataGridView1 高度的时候,如图3这个问题希望高手帮帮忙...
http://hi.csdn.net/attachment/200912/24/148499_12616267360nta.jpg
重绘(问题一)
http://hi.csdn.net/attachment/200912/24/148499_1261626743i0gC.jpg
重绘(问题二)
http://hi.csdn.net/attachment/200912/24/148499_1261626746RUZY.jpg我把重绘放在了 dataGridView1_RowPostPaint 事件里面.
因为 dataGridView1_ColumnWidthChanged 的时候 ,我才能实现重绘合计行的竖线...问题来了:
当我拖动(变大) dataGridView1 高度的时候,如图2这个问题
当我拖动(变小) dataGridView1 高度的时候,如图3这个问题希望高手帮帮忙...
private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
if ( e.RowIndex != -1 )
{
using ( Brush gridBrush = new SolidBrush(this.dataGridView1.GridColor), backColorBrush = new SolidBrush(e.InheritedRowStyle.BackColor) )
{
using ( Pen gridLinePen = new Pen(gridBrush) )
{
//画底色
Rectangle re = this.ClientRectangle;
re = new Rectangle(e.RowBounds.Left, this.dataGridView1.Height - 25, getDataGridViewWidth(), 25);
e.Graphics.FillRectangle(backColorBrush, re);
e.Graphics.DrawArc(gridLinePen, re, 12, 84);
e.Graphics.DrawRectangle(gridLinePen, re);
// 画合计
e.Graphics.DrawString("合计", this.Font, new SolidBrush(this.dataGridView1.DefaultCellStyle.ForeColor), 5, this.dataGridView1.Height - 21); // 画横线顶部
e.Graphics.DrawLine(gridLinePen,
e.RowBounds.Left,
this.dataGridView1.Height - 2,
e.RowBounds.Right,
this.dataGridView1.Height - 2);
// 画横线底部
e.Graphics.DrawLine(gridLinePen,
e.RowBounds.Left,
this.dataGridView1.Height - 23,
e.RowBounds.Right,
this.dataGridView1.Height - 23);
// 画竖线边线
float _sum = 0;
int intAllWidth = 0; if ( dataGridView1.RowHeadersVisible )
{
intAllWidth += dataGridView1.RowHeadersWidth - 1;
e.Graphics.DrawLine(gridLinePen,
intAllWidth,
this.dataGridView1.Height - 24,
intAllWidth,
this.dataGridView1.Height - 2);
}
for ( int n = 0 ; n < this.dataGridView1.Columns.Count ; n++ )
{
intAllWidth += dataGridView1.Columns[ n ].Width; e.Graphics.DrawLine(gridLinePen,
intAllWidth,
this.dataGridView1.Height - 24,
intAllWidth,
this.dataGridView1.Height - 2);
if ( IsNumeric(this.dataGridView1.Columns[ n ].DataPropertyName) )
{
for ( int i = 0 ; i < this.dataGridView1.Rows.Count - 1 ; i++ )
{
_sum += float.Parse(this.dataGridView1.Rows[ i ].Cells[ n ].Value.ToString());
}
e.Graphics.DrawString(_sum.ToString(), this.Font, new SolidBrush(this.dataGridView1.DefaultCellStyle.ForeColor), intAllWidth - this.dataGridView1.Columns[ n ].Width, this.dataGridView1.Height - 21);
}
}
}
}
}
{
DataGridView.Refresh(); //先执行这个看看
}
是你定义的最终区域把如果定义成全局变量 private Rectangle re = new Rectangle ();