Printing a datagridview...
-
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) -
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)What additional information is needed to aid in resolving this issue? I need to be able to print my column names horizontal. I can not seem to figure this out when going to the printer. Please help.