A
Adam Sandler
Hello,
I took a look at http://msdn.microsoft.com/en-us/library/aa287531(VS.71).aspx
which gives a code sample on how to print a form. To print a panel, I
just substituted 'p' for 'this':
private void CaptureScreen(Panel p)
{
Graphics myGraphics = p.CreateGraphics();
Size s = p.Size;
memoryImage = new Bitmap(s.Width, s.Height, myGraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
IntPtr dc1 = myGraphics.GetHdc();
IntPtr dc2 = memoryGraphics.GetHdc();
BitBlt(dc2, 0, 0, p.ClientRectangle.Width,
p.ClientRectangle.Height, dc1, 0, 0, 13369376);
myGraphics.ReleaseHdc(dc1);
memoryGraphics.ReleaseHdc(dc2);
}
private void printDocument1_PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(memoryImage, 0, 0);
}
Unfortunately, the output is sketchy... the capture even gets portions
of the screen which is not part of the application... for example, I
see the start menu button and taskbar in the print.
Is this the only way to print my panel? Basically, the panel I'm
trying to print just contains other, smaller, panels aligned in a grid
format. Each of the smaller panel just has a label inside.
Suggestions are greatly appreciated.
Thanks!
I took a look at http://msdn.microsoft.com/en-us/library/aa287531(VS.71).aspx
which gives a code sample on how to print a form. To print a panel, I
just substituted 'p' for 'this':
private void CaptureScreen(Panel p)
{
Graphics myGraphics = p.CreateGraphics();
Size s = p.Size;
memoryImage = new Bitmap(s.Width, s.Height, myGraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
IntPtr dc1 = myGraphics.GetHdc();
IntPtr dc2 = memoryGraphics.GetHdc();
BitBlt(dc2, 0, 0, p.ClientRectangle.Width,
p.ClientRectangle.Height, dc1, 0, 0, 13369376);
myGraphics.ReleaseHdc(dc1);
memoryGraphics.ReleaseHdc(dc2);
}
private void printDocument1_PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(memoryImage, 0, 0);
}
Unfortunately, the output is sketchy... the capture even gets portions
of the screen which is not part of the application... for example, I
see the start menu button and taskbar in the print.
Is this the only way to print my panel? Basically, the panel I'm
trying to print just contains other, smaller, panels aligned in a grid
format. Each of the smaller panel just has a label inside.
Suggestions are greatly appreciated.
Thanks!