2014-09-30 32 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