void dataGridView1_Paint(object sender, PaintEventArgs e)
{
//Get the cell bounds of the header cell in column3
Rectangle r1 = this.dataGridView1.GetCellDisplayRectangle(2, -1, true);
//Get the cell bounds of the header cell in column4
Rectangle r2 = this.dataGridView1.GetCellDisplayRectangle(3, -1, true);
r1.X += 1;
r1.Y += 2;
r1.Width += r2.Width - 2;
r1.Height -= 6;
//cover the rectangle right over the headers.
using (SolidBrush br = new SolidBrush(
this.dataGridView1.ColumnHeadersDefaultCellStyle.BackColor))
{
e.Graphics.FillRectangle(br, r1);
}
//draw text
using (SolidBrush br = new SolidBrush(
this.dataGridView1.ColumnHeadersDefaultCellStyle.ForeColor))
{
StringFormat sf = new StringFormat();
sf.LineAlignment = StringAlignment.Center;
sf.Alignment = StringAlignment.Center;
e.Graphics.DrawString("merged header",
this.dataGridView1.ColumnHeadersDefaultCellStyle.Font, br, r1, sf);
}
}
|
No responses found. Be the first to respond and make money from revenue sharing program.
|