2014-04-24 3 views
2

기본 데이터 표보기 선보다 두꺼운 선이 필요하기 때문에 자체 그리드 선을 그려야합니다. 이것은 내가 그것을 어떻게 사용하고 코드입니다 :사용자 지정 DataGridView 셀 페인팅

private void dgv_Wafer_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) 
    { 
     using (Pen p = new Pen(Brushes.Black, 12)) 
     { 
      e.Graphics.DrawLine(p, new Point(0, e.CellBounds.Bottom), new Point(e.CellBounds.Right, e.CellBounds.Bottom)); 
     } 
     using (Pen p = new Pen(Brushes.Black, 6)) 
     { 
      e.Graphics.DrawLine(p, new Point(e.CellBounds.Right, 0), new Point(e.CellBounds.Right - 1, e.CellBounds.Bottom)); 
     } 
    } 

선이 그려집니다하지만 수평 라인이 마지막 열에서 그려지지 않습니다 수직 라인이 마지막 행에 그려지지 않습니다. 선이 너무 작은 열과 행 인 격자를 만듭니다. 누구든지이 문제를 해결하는 방법을 알고 있습니까?

답변

3

그림을 제어하기 위해 e.Handled = true;을 설정해보십시오. 세포의 기본 회화에 다시 추가

귀하의 코드는 왼쪽 상단,하지만 당신은 사용해야 있도록 CellBounds이 값이 컨트롤의 내부 공간을 기반으로 0을 사용하고 있었다
e.PaintBackground(e.ClipBounds, true); 
e.PaintContent(e.ClipBounds); 
using (Pen p = new Pen(Brushes.Black, 12)) { 
    e.Graphics.DrawLine(p, new Point(e.CellBounds.Left, e.CellBounds.Bottom), 
         new Point(e.CellBounds.Right, e.CellBounds.Bottom)); 
} 
using (Pen p = new Pen(Brushes.Black, 6)) { 
    e.Graphics.DrawLine(p, new Point(e.CellBounds.Right, e.CellBounds.Top), 
         new Point(e.CellBounds.Right, e.CellBounds.Bottom)); 
} 
e.Handled = true; 

e.CellBounds.Lefte.CellBounds.Top

그 경계의 두께를 고려하여 선의 점을 조정할 수도 있습니다.이 선들은 현재 셀 외부에서 출혈하고 있습니다.

+0

완벽하게 작동 해 주셔서 감사합니다. – user3194708