图片表示对上述问题,当绘制了自定义绘制边框:相邻的单元格(顶部和左)选择
下面是我使用的周围绘制边框选择单元格代码:
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.ColumnIndex > 0 && e.RowIndex > -1)
{
if (e.Value != null && (!e.Value.Equals("0")) && (!e.Value.Equals("-")))
{
double d = Convert.ToDouble(e.Value);
if (e.ColumnIndex == 2)
{
int limit = Convert.ToInt16(numericUpDown1.Value);
if (d > limit)
{
int pWidth = 1;
Pen p = new Pen(Color.Red, pWidth);
e.PaintBackground(e.CellBounds, true);
e.PaintContent(e.CellBounds);
int x = e.CellBounds.Left – pWidth;
int y = e.CellBounds.Top – pWidth;
int w = e.CellBounds.Width;
int h = e.CellBounds.Height;
e.Graphics.DrawRectangle(p, x,y,w,h);
e.Handled = true;
}
}
}
}
}
有没有办法让它们不消失?它不会发生在底部和右边界。我已经试过几件事情包括:
- 禁用边框和拉丝我自己的所有细胞(同样的问题)
- 调整绘制矩形是细胞内(不喜欢看)
- 处理CellEnter/CellLeave/CellClick到.Invalidate的行和列,企图获取自定义边框细胞在上面