0
我有一個數據網格視圖,我想使所有單元格邊框更厚。有沒有可以做到這一點的財產?更改DataGridViews中的所有單元格邊框寬度
我有一個數據網格視圖,我想使所有單元格邊框更厚。有沒有可以做到這一點的財產?更改DataGridViews中的所有單元格邊框寬度
您需要通過將代碼添加到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);
}
}
這使得datagridview沒有邊框。我將如何改變厚度? – user3194708
請參閱http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewadvancedborderstyle.aspx –