المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Printing a datagridview...



C# Programming
11-29-2009, 04:10 PM
I have several columns I want to print the column headers vertically and not horizontal.
I have found a method that works but does not meet the expectations speficied.
Option 1) (This way does not meet specifications but does work)
- I could loop thru the string placing a carrage return after each letter.

Option 2) (This way meets specifications and I can get it to print on the screen. However I can not get it to print onto the printer)
private void dgvReport_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{

if (e.RowIndex == -1 && e.ColumnIndex >= 4)
{
e.PaintBackground(e.ClipBounds, true);
Rectangle rect =
this.dgvReport.GetColumnDisplayRectangle(e.ColumnIndex, true);
Size titleSize =
TextRenderer.MeasureText(e.Value.ToString(), e.CellStyle.Font);
if (this.dgvReport.ColumnHeadersHeight < titleSize.Width)
this.dgvReport.ColumnHeadersHeight = titleSize.Width;

e.Graphics.TranslateTransform(0, titleSize.Width);
e.Graphics.RotateTransform(-90.0F);

e.Graphics.DrawString(e.Value.ToString(), e.CellStyle.Font, //this.Font,
Brushes.Black, new PointF(rect.Y, rect.X));

e.Graphics.RotateTransform(90.0F);
e.Graphics.TranslateTransform(0, -titleSize.Width);
e.Handled = true;
}

}

This way actually rotates the column headers to ensure their vertical the same as their horizontal.

How can I print this way (Option 2)