G
Guest
Hi,
I have a form with tab pages on it, and I'd like to print each page whenever
a button is pressed (all the tabpages share the same print button - I just
give it a different parent when another tab is pressed). But I can only print
once. When the print button is pressed the second time, I get error
An unhandled exception of type
'System.Runtime.InteropServices.ExternalException' occurred in
system.drawing.dll
Additional information: A generic error occurred in GDI+.
I'm not sure what to do here. My code is below. I commented out the
pd.Print(); and it worked fine. No exceptions, and the bitmaps saved fine
each time. I also tried giving the PrintDocument a different name each time,
and it still isn't happy.
private void printClick(object sender, System.EventArgs e)
{
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);
PrintDocument pd = new PrintDocument();
PageSetupDialog pg = new PageSetupDialog();
printDialog1.Document = pd;
pg.Document = pd;
pg.PageSettings.Landscape = true;
DialogResult result = printDialog1.ShowDialog();
if (result==DialogResult.OK)
{pd.PrintPage += new
System.Drawing.Printing.PrintPageEventHandler(PrintCurrentPage); pd.Print();}
pd.Dispose();
}
Thanks for any help!!!
Mel
I have a form with tab pages on it, and I'd like to print each page whenever
a button is pressed (all the tabpages share the same print button - I just
give it a different parent when another tab is pressed). But I can only print
once. When the print button is pressed the second time, I get error
An unhandled exception of type
'System.Runtime.InteropServices.ExternalException' occurred in
system.drawing.dll
Additional information: A generic error occurred in GDI+.
I'm not sure what to do here. My code is below. I commented out the
pd.Print(); and it worked fine. No exceptions, and the bitmaps saved fine
each time. I also tried giving the PrintDocument a different name each time,
and it still isn't happy.
private void printClick(object sender, System.EventArgs e)
{
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);
PrintDocument pd = new PrintDocument();
PageSetupDialog pg = new PageSetupDialog();
printDialog1.Document = pd;
pg.Document = pd;
pg.PageSettings.Landscape = true;
DialogResult result = printDialog1.ShowDialog();
if (result==DialogResult.OK)
{pd.PrintPage += new
System.Drawing.Printing.PrintPageEventHandler(PrintCurrentPage); pd.Print();}
pd.Dispose();
}
Thanks for any help!!!
Mel