|
我用的重载Paint方法,虽然实现了样式控制,但是一改变当前行样式就没了,不知道为什么?急需帮忙!谢谢了先.
下面是我实现的代码:
public void dataGrid1_Paint(object sender, PaintEventArgs e)
{
try
{
Rectangle currRct;
for (int i = 0; i < this.dataGrid1.VisibleRowCount; i++)
{
currRct = (Rectangle)this.dataGrid1.GetCellBounds(i, 0);
e.Graphics.DrawString(string.Format(" {0}", i + 1), this.Font, new SolidBrush(Color.Green), 10, currRct.Y + 2);
}
base.OnPaint(e);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
try
{
int i;
for (i = 0; i < dataGrid1.VisibleRowCount; i++)
{
for (int j = 0; j < 3; j++)//未读过的加样式
{
string temp = dataGrid1[i, j].ToString();
e.Graphics.FillRectangle(new SolidBrush(Color.Red), dataGrid1.GetCellBounds(i, j));
e.Graphics.DrawString(temp, dataGrid1.Font, new SolidBrush(Color.Black), dataGrid1.GetCellBounds(i, j).Left + 2, dataGrid1.GetCellBounds(i, j).Top + 2);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
|
|