471,317 Members | 1,837 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,317 software developers and data experts.

printing problem

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
0 945

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Programatix | last post: by
reply views Thread by Programatix | last post: by
5 posts views Thread by Stefania Scott | last post: by
5 posts views Thread by C-Services Holland b.v. | last post: by
2 posts views Thread by Teemu | last post: by
2 posts views Thread by Sukh | last post: by
18 posts views Thread by Brett | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.