Re: Printing a Panel
- From: "Leo Seccia" <lseccia@xxxxxxx>
- Date: Tue, 10 Jun 2008 10:59:25 +0100
Hello Adam,
Did you try to use the CopyFromScreen method instead GetHdc and IntPtrs... You might have more luck that way...
eg.
[..]
// Set the bitmap object to the size of the screen
bmpScreenshot = new Bitmap(regionSize.Width, regionSize.Height, PixelFormat.Format32bppArgb);
// Create a graphics object from the bitmap
gfxScreenshot = Graphics.FromImage(bmpScreenshot);
// Take the screenshot from the upper left corner to the right bottom corner
gfxScreenshot.CopyFromScreen(offsetX, offsetY, 0, 0, regionSize, CopyPixelOperation.SourceCopy);
[..]
I use this code to do something very similar to what you want to do. And it works.
Best of luck to you.
Leo
"Adam Sandler" <corn29@xxxxxxxxxx> wrote in message news:f0cf5e1d-d61b-42ac-a126-663faa17a85b@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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!
.
- Follow-Ups:
- Re: Printing a Panel
- From: Adam Sandler
- Re: Printing a Panel
- References:
- Printing a Panel
- From: Adam Sandler
- Printing a Panel
- Prev by Date: Re: About using correct terminologi
- Next by Date: Re: printing ASCII character greater than 0x7f
- Previous by thread: Re: Printing a Panel
- Next by thread: Re: Printing a Panel
- Index(es):
Relevant Pages
|