2011-05-18 23 views
5

Sadece ContentGridView hücresinin Content'inin arkaplanını boyamam gerekiyor.Ama resim yaparken boyasını da boyayorum.Lütfen bana yardımcı olun.Sadece DataGridView'ın hücre arka planı nasıl değil?

Kodum böyle gider. Eğer hücre arka plan rengini değiştirmek için CellPainting olayı yakalamak neden ihtiyaç

private void Daywisegrid_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) 
     { 
      if (e.RowIndex == 0) 

      { 
       using (Brush gridBrush = new SolidBrush(this.Daywisegrid.GridColor)) 
       { 
        using (Brush backColorBrush = new SolidBrush(e.CellStyle.BackColor)) 
        { 
         using (Pen gridLinePen = new Pen(gridBrush)) 
         { 
          // Clear cell 
          e.Graphics.FillRectangle(backColorBrush, e.CellBounds); 
          //Bottom line drawing 
          e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left, e.CellBounds.Bottom-1 , e.CellBounds.Right, e.CellBounds.Bottom-1); 


          e.Handled = true; 
         } 
        } 
       } 
      } 

cevap

8


ben sadece bu

Daywisegrid.Rows[RowIndex].Cells[columnIndex].Style.BackColor = Color.Red; 

gibi yapmak Ama resminde yapmak istiyorsanız bu

deneyin emin değilim
private void Daywisegrid_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) 
     { 
      if (e.RowIndex == 0) 

      { 
       using (Brush gridBrush = new SolidBrush(this.Daywisegrid.GridColor)) 
       { 
        using (Brush backColorBrush = new SolidBrush(e.CellStyle.BackColor)) 
        { 
         using (Pen gridLinePen = new Pen(gridBrush)) 
         { 
          // Clear cell 
          e.Graphics.FillRectangle(backColorBrush, e.CellBounds); 
          //Bottom line drawing 
          e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left, e.CellBounds.Bottom-1 , e.CellBounds.Right, e.CellBounds.Bottom-1); 

           // here you force paint of content 
          e.PaintContent(e.ClipBounds ); 
          e.Handled = true; 
         } 
        } 
       } 
      } 
0

olmalı

e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left, e.CellBounds.Bottom-1 , e.CellBounds.Right - 1, e.CellBounds.Bottom - 1); 

e.CellBounds.Right, e.CellBounds.Bottom - 1 noktası, bir sonraki hücre tarafından silinir.

İlgili konular