2014-04-21 90 views

回答

0

您需要通過將代碼添加到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); 
    } 
} 
+0

這使得datagridview沒有邊框。我將如何改變厚度? – user3194708

+0

請參閱http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewadvancedborderstyle.aspx –

相關問題