Please help. Printing datagridview issue...
-
I have learned a lot doing this project with datagrid views. But I have one issue though minor to me is a major issue to the client. I have been working on this for over 2 weeks and can not find any examples to give me the output I am looking for. Please Help any Ideas please: What I need to be able to do is essentially print my database grid column header names vertically at a 90.0F angle. Not horizontally as the default. I have learned how to do this to the grid itself so it prints correctly on the screen. Which is:
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; } }
But When I send the grid to the printer the columns are all horizontal not vertical. What can I do to print the columns vertical. Any examples anywhere?
-
I have learned a lot doing this project with datagrid views. But I have one issue though minor to me is a major issue to the client. I have been working on this for over 2 weeks and can not find any examples to give me the output I am looking for. Please Help any Ideas please: What I need to be able to do is essentially print my database grid column header names vertically at a 90.0F angle. Not horizontally as the default. I have learned how to do this to the grid itself so it prints correctly on the screen. Which is:
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; } }
But When I send the grid to the printer the columns are all horizontal not vertical. What can I do to print the columns vertical. Any examples anywhere?
Found the solution
StringFormat CellFormat = new StringFormat();
//CellFormat.Trimming = StringTrimming.Word;
CellFormat.FormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.NoClip | StringFormatFlags.NoWrap | StringFormatFlags.DirectionVertical;
CellFormat.Alignment = StringAlignment.Center;g.DrawString(column.HeaderText,
cell.Font(scale),
new SolidBrush(cell.ForeColor()),
CellBounds,
CellFormat);The StringFormatFlags.DirectionVertical transforms the text vertically. Their is no need to picture draw the text vertically.