Tuesday, October 6, 2009

How can I show vertical text in the cell?

void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)

{

if (e.ColumnIndex == 0 && e.RowIndex > -1 && e.Value != null)

{

e.Paint(e.CellBounds, DataGridViewPaintParts.All

& ~DataGridViewPaintParts.ContentForeground);

StringFormat sf = new StringFormat();

sf.Alignment = StringAlignment.Center;

sf.LineAlignment = StringAlignment.Center;

sf.FormatFlags = StringFormatFlags.DirectionVertical;

e.Graphics.DrawString(e.Value.ToString(), e.CellStyle.Font,

new SolidBrush(e.CellStyle.ForeColor), e.CellBounds, sf);

e.Handled = true;

}

}

No comments:

Post a Comment