A
Ashutosh
Hi,
How can I find out the width in pixel that a particular text requires to
be drawn/written on a graphics object. (Similar to VC++ CDC::GetTextExtent)
I am displaying some data in DataGridView and the column headers are
vertical. So, I need to resize the header cell's height based on the max
space required to display the longest header text. This must be done at
runtime as there is no information of the data that will be displayed in
the grid.
I am using the following text to change the orientation of the displayed
text.
private void dataGridView1_CellPainting(object sender,
DataGridViewCellPaintingEventArgs e)
{
if (e.RowIndex == -1 && e.ColumnIndex >= 0)
{
e.PaintBackground(e.CellBounds, true);
e.Graphics.TranslateTransform(e.CellBounds.Left,
e.CellBounds.Bottom);
e.Graphics.RotateTransform(270);
e.Graphics.DrawString(e.FormattedValue.ToString(),
e.CellStyle.Font, Brushes.Black, 5, 5);
e.Graphics.ResetTransform();
e.Handled = true;
}
}
Thanks & Regards,
Ashutosh
How can I find out the width in pixel that a particular text requires to
be drawn/written on a graphics object. (Similar to VC++ CDC::GetTextExtent)
I am displaying some data in DataGridView and the column headers are
vertical. So, I need to resize the header cell's height based on the max
space required to display the longest header text. This must be done at
runtime as there is no information of the data that will be displayed in
the grid.
I am using the following text to change the orientation of the displayed
text.
private void dataGridView1_CellPainting(object sender,
DataGridViewCellPaintingEventArgs e)
{
if (e.RowIndex == -1 && e.ColumnIndex >= 0)
{
e.PaintBackground(e.CellBounds, true);
e.Graphics.TranslateTransform(e.CellBounds.Left,
e.CellBounds.Bottom);
e.Graphics.RotateTransform(270);
e.Graphics.DrawString(e.FormattedValue.ToString(),
e.CellStyle.Font, Brushes.Black, 5, 5);
e.Graphics.ResetTransform();
e.Handled = true;
}
}
Thanks & Regards,
Ashutosh