Reputation: 31
this is my panel1 paint event
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);
help me same method on datagridview cell paint event apply. i want drawing drawline on datagridview cell
Upvotes: 1
Views: 3270
Reputation: 2812
this is not good for real application, but if you Have TO do this, you can use this
//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;
}
}
and the result is same as this:
But, As I told before, don't use this to real application
Upvotes: 1