2014-09-30 34 views
1

這是我PANEL1漆事件繪製的水平線,一個DataGridView細胞

Pen graphPen = new Pen(Color.White, 10); 
PointF pt1D = new PointF(); 
PointF pt2D = new PointF(); 
pt1D.X = 5; 
pt1D.Y = 10; 
pt2D.X = 175; 
pt2D.Y = 10; 

e.Graphics.DrawLine(graphPen, pt1D, pt2D); 
e.Graphics.DrawLine(graphPen, 5, 10, 175, 10); 

幫我datagridview的電池漆事件同樣的方法適用。 我想對datagridview的細胞

回答

1

,這是不利於實際應用繪製的DrawLine,但如果你必須做到這一點,你可以使用這個

//subscribing the event 
dataGridView1.CellPainting += dataGridView1_CellPainting; 

//handle the event 
void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) 
{ 

    if (e.RowIndex >= 0 && e.ColumnIndex >= 0) 
    { 
     e.Graphics.DrawLine(Pens.Red, e.CellBounds.Left, e.CellBounds.Top, e.CellBounds.Right, e.CellBounds.Bottom); 
     e.Graphics.DrawLine(Pens.Blue, e.CellBounds.Left, e.CellBounds.Top+e.CellBounds.Height/2, e.CellBounds.Right,e.CellBounds.Top+ e.CellBounds.Height/2); 

     e.Paint(e.ClipBounds, DataGridViewPaintParts.ContentForeground); 
     e.Handled = true; 
    } 
} 

,結果是一樣的:

enter image description here

但是,正如我前面說,不要用這個實際應用

+0

k,謝謝,但actuallu我想要如果我雙擊任何單元格它將被顯示提起矩形顏色再次我雙擊它的hide.this是我想要的。 – Varta 2014-09-30 12:35:59

+0

請編輯您的問題 – 2014-09-30 12:38:21