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 problem

printing problem

Scheduled Pinned Locked Moved C#
graphicshelpwinformsquestiondiscussion
2 Posts 2 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.
  • M Offline
    M Offline
    melanieab
    wrote on last edited by
    #1

    Hi, When the print button is clicked, I save a snapshot of the screen to a bitmap file. Graphics currentTab = this.CreateGraphics(); Size s = this.Size; Bitmap memoryImage = new Bitmap(s.Width - 10, s.Height - 36, currentTab); Graphics memoryGraphics = Graphics.FromImage(memoryImage); IntPtr dc1 = currentTab.GetHdc(); IntPtr dc2 = memoryGraphics.GetHdc(); BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 2, 2, 13369376); CurrentPage = memoryImage; currentTab.ReleaseHdc(dc1); memoryGraphics.ReleaseHdc(dc2); CurrentPage.Save("sCurrentPage.bmp",System.Drawing.Imaging.ImageFormat.Bmp); Then I start to do the printing. PrintDocument ppd = new PrintDocument(); PageSetupDialog pg = new PageSetupDialog(); printDialog1.Document = ppd; pg.Document = ppd; pg.PageSettings.Landscape = true; DialogResult result = printDialog1.ShowDialog(); if (result==DialogResult.OK) { ppd.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(PrintCurrentPage); ppd.Print(); } ppd.Dispose(); The first time I print, everything works ok. But if I hit the button again, I get an error, and the current screen doesn't save. (An unhandled exception of type 'System.Runtime.InteropServices.ExternalException' occurred in system.drawing.dll Additional information: A generic error occurred in GDI+.) If I comment out the printing part, the current page saves just fine. I also commented out just the line ppd.Print();. The image saved fine and I didn't get any error messages. Any thoughts? Cheers, Mel

    D 1 Reply Last reply
    0
    • M melanieab

      Hi, When the print button is clicked, I save a snapshot of the screen to a bitmap file. Graphics currentTab = this.CreateGraphics(); Size s = this.Size; Bitmap memoryImage = new Bitmap(s.Width - 10, s.Height - 36, currentTab); Graphics memoryGraphics = Graphics.FromImage(memoryImage); IntPtr dc1 = currentTab.GetHdc(); IntPtr dc2 = memoryGraphics.GetHdc(); BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 2, 2, 13369376); CurrentPage = memoryImage; currentTab.ReleaseHdc(dc1); memoryGraphics.ReleaseHdc(dc2); CurrentPage.Save("sCurrentPage.bmp",System.Drawing.Imaging.ImageFormat.Bmp); Then I start to do the printing. PrintDocument ppd = new PrintDocument(); PageSetupDialog pg = new PageSetupDialog(); printDialog1.Document = ppd; pg.Document = ppd; pg.PageSettings.Landscape = true; DialogResult result = printDialog1.ShowDialog(); if (result==DialogResult.OK) { ppd.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(PrintCurrentPage); ppd.Print(); } ppd.Dispose(); The first time I print, everything works ok. But if I hit the button again, I get an error, and the current screen doesn't save. (An unhandled exception of type 'System.Runtime.InteropServices.ExternalException' occurred in system.drawing.dll Additional information: A generic error occurred in GDI+.) If I comment out the printing part, the current page saves just fine. I also commented out just the line ppd.Print();. The image saved fine and I didn't get any error messages. Any thoughts? Cheers, Mel

      D Offline
      D Offline
      DigitalKing
      wrote on last edited by
      #2

      Where is the function: 'BitBlt'? Is it a Win32 function or is it somewhere in the .Net Framework, or did you write it? I get "system.drawing.dll Additional information: A generic error occurred in GDI+" in any application when I try to save a Bitmap to the same file more than once. Try changing the name of this file after every save. Ex: First time name would be "sCurrentPage0.bmp" then "sCurrentPage1.bmp" "sCurrentPage2.bmp"...

      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