工作中遇到一个情况,列头表示工位2,行头表示工位1,所以表头第一格用斜线。
这里用到DGI简单的绘制,以及dgv里面的Paint事件。在这之前用过Cellpaint事件,结果一直闪烁刷新。
(因为代码考不出来,下面是手打的,可能有拼错)
private void dataGridView1_Paint(object sender,PaintEventArgs e)
{
paintline(e,"工位1","工位2");
}
private void paintline(PaintEventArgs e,string name1,string name2)
{
Graphics gp=e.Graphics;
Rectangle rec=this.dataGridView1.GetCellDisplayRectangle(0,-1,false);
Brush gridBrush=new SolidBrush(Color.Black);
Pen gridLinePen=new Pen(gridBrush);
gp.DrawLine(gridLinePen,new Point(rec.X,rec.Y),new Point(rec.X+rec.Width,rec.Y+rec.Height));
gp.DrawString(name1,new Font("SimSun",9F),Brushes.Black,new Point(rec.X+rec.Width/8,rec.Y+rec.Height/3));
gp.DrawString(name2,new Font("SimSun",9F),Brushes.Black,new Point(rec.X+rec.Width/3,rec.Y+rec.Height/8));
}