【发布时间】:2014-04-21 22:07:38
【问题描述】:
我有一个数据网格视图,我想让所有的单元格边框变粗。有没有可以做到这一点的属性?
【问题讨论】:
标签: c# visual-studio-2010 datagridview
我有一个数据网格视图,我想让所有的单元格边框变粗。有没有可以做到这一点的属性?
【问题讨论】:
标签: c# visual-studio-2010 datagridview
您需要通过向CellPainting 事件处理程序添加代码来进行一些自定义绘制。要将单元格边框设置为无,请使用 CellBorderStyle:
dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None;
// CellPainting event handler for your dataGridView1
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.RowIndex == -1 && e.ColumnIndex > -1)
{
e.Handled = true;
using (Brush b = new SolidBrush(dataGridView1.DefaultCellStyle.BackColor))
{
e.Graphics.FillRectangle(b, e.CellBounds);
}
using (Pen p = new Pen(Brushes.Black))
{
p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
e.Graphics.DrawLine(p, new Point(0, e.CellBounds.Bottom-1), new Point(e.CellBounds.Right, e.CellBounds.Bottom-1));
}
e.PaintContent(e.ClipBounds);
}
}
【讨论】: