2017-03-10 10 views
0

DataGridView 셀을 HatchPattern으로 채울 방법이 있습니까?해치 패턴이있는 DataGridView 셀 채우기

나는 dataGridView1.Rows [n] .Cells [m] .Style을 사용하여 시도했지만이 방법으로는 셀의 배경색 만 변경할 수 있습니다.

+0

_HatchPattern_이 무엇을 의미합니까? 당신이 무엇을 요구하고 있는지 불분명하다 – Pikoh

+0

두 가지 색과 HatchStyle로 만들어진 HatchBrush 개체를 사용하여 셀을 채 웁니다. 모양을 채우는 데 주로 사용됩니다. – Szczepan

+0

왜 그렇게 할 지 이해할 수 없지만 [이 질문] (http://stackoverflow.com/q/6041044/579895)을 참조하십시오. – Pikoh

답변

1

당신은 소유자 그리기 에 셀, 즉 코드 CellPainting 이벤트 .. 나는 내용의 가독성 반투명 해치 색상을 만들어

using System.Drawing.Drawing2D; 
.. 
private void dataGridView1_CellPainting(object sender, 
             DataGridViewCellPaintingEventArgs e) 
{ 
    Rectangle cr = e.CellBounds; 
    e.PaintBackground(cr, true); 

    Color c1 = Color.FromArgb(64, Color.GreenYellow); 
    Color c2 = Color.FromArgb(64, e.State == DataGridViewElementStates.Selected ? 
       Color.HotPink : Color.RosyBrown) ; 

    if (e.RowIndex == 2 && (e.ColumnIndex >= 3)) 
     using (HatchBrush brush = new HatchBrush(HatchStyle.LargeConfetti, c1, c2)) 
     { 
      e.Graphics.FillRectangle(brush, cr); 
     } 
    e.PaintContent(cr); 
} 

enter image description here

주의가 필요합니다 . 또한 셀 중 하나만 선택했는지 확인합니다.