Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Printing a datagridview...

Printing a datagridview...

Scheduled Pinned Locked Moved C#
graphicsquestion
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JollyMansArt
    wrote on last edited by
    #1

    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)

    J 1 Reply Last reply
    0
    • J JollyMansArt

      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)

      J Offline
      J Offline
      JollyMansArt
      wrote on last edited by
      #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.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups