By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,012 Members | 1,278 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,012 IT Pros & Developers. It's quick & easy.

printing problem

P: n/a
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(Prin tCurrentPage);
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

Jan 13 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.