How to print using multiple screenshots captured with copyfromscreen
I'm pretty new to C# but I finally have my first program up and running
and I need to make it print. Its a window form with information and
calculations on different tab controls, somewhat like Excel. The page that
is currently being looked at prints fine with the copyfromscreen method,
but I cannot get additional pages to print correctly. I have about 20 tabs
I would like to be able to print at one time. I found a way to print the
contents of controls into a textfile, but I would much prefer to be able
to print what the form looks like. Thanks.
Bitmap memoryImage;
Bitmap memoryImage2;
private void CaptureScreen()
{
Graphics myGraphics = this.CreateGraphics();
Size s = tabControlMain.Size;
s.Width = s.Width + 20;
memoryImage = new Bitmap(s.Width, s.Height, myGraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
memoryGraphics.CopyFromScreen(this.Location.X+15,
this.Location.Y+80, 0, 0, s);
tabControlMain.SelectedIndex = 1;
memoryImage2 = new Bitmap(s.Width, s.Height, myGraphics);
Graphics memoryGraphics2 = Graphics.FromImage(memoryImage2);
memoryGraphics2.CopyFromScreen(this.Location.X + 15,
this.Location.Y + 80, 0, 0, s);
}
private void printDocumentReal_PrintPage(System.Object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(memoryImage, 0, 0);
e.Graphics.DrawImage(memoryImage2, 0, 550);
}
private void printToolStripButton_Click(object sender, EventArgs e)
{
CaptureScreen();
printDocumentReal.Print();
}
No comments:
Post a Comment