Hi,
When the print button is clicked, I save a snapshot of the screen to a
bitmap file.
Graphics currentTab = this.CreateGrap hics();
Size s = this.Size;
Bitmap memoryImage = new Bitmap(s.Width - 10, s.Height - 36, currentTab);
Graphics memoryGraphics = Graphics.FromIm age(memoryImage );
IntPtr dc1 = currentTab.GetH dc();
IntPtr dc2 = memoryGraphics. GetHdc();
BitBlt(dc2, 0, 0, this.ClientRect angle.Width, this.ClientRect angle.Height,
dc1, 2, 2, 13369376);
CurrentPage = memoryImage;
currentTab.Rele aseHdc(dc1);
memoryGraphics. ReleaseHdc(dc2) ;
CurrentPage.Sav e("sCurrentPage .bmp",System.Dr awing.Imaging.I mageFormat.Bmp) ;
Then I start to do the printing.
PrintDocument ppd = new PrintDocument() ;
PageSetupDialog pg = new PageSetupDialog ();
printDialog1.Do cument = ppd;
pg.Document = ppd;
pg.PageSettings .Landscape = true;
DialogResult result = printDialog1.Sh owDialog();
if (result==Dialog Result.OK)
{
ppd.PrintPage += new
System.Drawing. Printing.PrintP ageEventHandler (PrintCurrentPa ge);
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 .InteropService s.ExternalExcep tion' 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
When the print button is clicked, I save a snapshot of the screen to a
bitmap file.
Graphics currentTab = this.CreateGrap hics();
Size s = this.Size;
Bitmap memoryImage = new Bitmap(s.Width - 10, s.Height - 36, currentTab);
Graphics memoryGraphics = Graphics.FromIm age(memoryImage );
IntPtr dc1 = currentTab.GetH dc();
IntPtr dc2 = memoryGraphics. GetHdc();
BitBlt(dc2, 0, 0, this.ClientRect angle.Width, this.ClientRect angle.Height,
dc1, 2, 2, 13369376);
CurrentPage = memoryImage;
currentTab.Rele aseHdc(dc1);
memoryGraphics. ReleaseHdc(dc2) ;
CurrentPage.Sav e("sCurrentPage .bmp",System.Dr awing.Imaging.I mageFormat.Bmp) ;
Then I start to do the printing.
PrintDocument ppd = new PrintDocument() ;
PageSetupDialog pg = new PageSetupDialog ();
printDialog1.Do cument = ppd;
pg.Document = ppd;
pg.PageSettings .Landscape = true;
DialogResult result = printDialog1.Sh owDialog();
if (result==Dialog Result.OK)
{
ppd.PrintPage += new
System.Drawing. Printing.PrintP ageEventHandler (PrintCurrentPa ge);
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 .InteropService s.ExternalExcep tion' 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