Hello,
I took a look at http://msdn.microsoft.com/en-us/libr...31(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(P anel p)
{
Graphics myGraphics = p.CreateGraphic s();
Size s = p.Size;
memoryImage = new Bitmap(s.Width, s.Height, myGraphics);
Graphics memoryGraphics = Graphics.FromIm age(memoryImage );
IntPtr dc1 = myGraphics.GetH dc();
IntPtr dc2 = memoryGraphics. GetHdc();
BitBlt(dc2, 0, 0, p.ClientRectang le.Width,
p.ClientRectang le.Height, dc1, 0, 0, 13369376);
myGraphics.Rele aseHdc(dc1);
memoryGraphics. ReleaseHdc(dc2) ;
}
private void printDocument1_ PrintPage(objec t sender,
System.Drawing. Printing.PrintP ageEventArgs e)
{
e.Graphics.Draw Image(memoryIma ge, 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! 5 5865
On Mon, 09 Jun 2008 21:33:47 -0700, Adam Sandler <co****@excite. comwrote:
[...]
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.
That's some odd code. As a general suggestion, you may want to try to
avoid using .NET 1.1 samples. :)
A lot of stuff has been added to .NET since then and there are usually
much more convenient ways to approach problems. As an example, the code
you're showing has basically been replaced by Control.DrawToB itmap and/or
Graphics.CopyFr omScreen.
Of course, either of those would still have similar issues to what you've
seen. Graphics.CopyFr omScreen for obvious reasons would, but it turns out
that Control.DrawToB itmap does too. Unfortunately, there is no 100%
reliable answer to your question. However, one thing you might want to
look at is using p/invoke to send a WM_PRINT message to the form you're
trying to print. The message isn't guaranteed to be supported by every
window, but I think that for the built-in Windows stuff it usually is.
Pete
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(regionSi ze.Width, regionSize.Heig ht,
PixelFormat.For mat32bppArgb);
// Create a graphics object from the bitmap
gfxScreenshot = Graphics.FromIm age(bmpScreensh ot);
// Take the screenshot from the upper left corner to the right
bottom corner
gfxScreenshot.C opyFromScreen(o ffsetX, offsetY, 0, 0, regionSize,
CopyPixelOperat ion.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" <co****@excite. comwrote in message
news:f0******** *************** ***********@q27 g2000prf.google groups.com...
Hello,
I took a look at http://msdn.microsoft.com/en-us/libr...31(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(P anel p)
{
Graphics myGraphics = p.CreateGraphic s();
Size s = p.Size;
memoryImage = new Bitmap(s.Width, s.Height, myGraphics);
Graphics memoryGraphics = Graphics.FromIm age(memoryImage );
IntPtr dc1 = myGraphics.GetH dc();
IntPtr dc2 = memoryGraphics. GetHdc();
BitBlt(dc2, 0, 0, p.ClientRectang le.Width,
p.ClientRectang le.Height, dc1, 0, 0, 13369376);
myGraphics.Rele aseHdc(dc1);
memoryGraphics. ReleaseHdc(dc2) ;
}
private void printDocument1_ PrintPage(objec t sender,
System.Drawing. Printing.PrintP ageEventArgs e)
{
e.Graphics.Draw Image(memoryIma ge, 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!
On Jun 10, 3:59 am, "Leo Seccia" <lsec...@msn.co mwrote:
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(regionSi ze.Width, regionSize.Heig ht,
PixelFormat.For mat32bppArgb);
// Create a graphics object from the bitmap
gfxScreenshot = Graphics.FromIm age(bmpScreensh ot);
// Take the screenshot from the upper left corner to the right
bottom corner
gfxScreenshot.C opyFromScreen(o ffsetX, offsetY, 0, 0, regionSize,
CopyPixelOperat ion.SourceCopy) ;
[..]
I use this code to do something very similar to what you want to do. And it
works.
Excellent... this works. Thank-you very much for the assistance.
I do have one question though when event is fired, the capture gets
the menuitem, from where the click occurs, in the image. Is there a
way to delay calling the capture function until the menuitem goes
away?
Thanks!
I'm glad it worked.
You could try something like:
Application.DoE vents();
System.Threadin g.Thread.Sleep( 1000); //or less than a
second...
(But of course, that is a bit of a bodge... :-) )
Optionally, you might try to bring the panel to front or hide the menu item
before taking the screenshot...
Good luck to you. Let me know how you solve this one.
Regards,
Leo
"Adam Sandler" <co****@excite. comwrote in message
news:b3******** *************** ***********@u36 g2000prf.google groups.com...
On Jun 10, 3:59 am, "Leo Seccia" <lsec...@msn.co mwrote:
>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(regionSi ze.Width, regionSize.Hei ght, PixelFormat.Fo rmat32bppArgb);
// Create a graphics object from the bitmap gfxScreenshot = Graphics.FromIm age(bmpScreensh ot);
// Take the screenshot from the upper left corner to the right bottom corner gfxScreenshot.C opyFromScreen(o ffsetX, offsetY, 0, 0, regionSize, CopyPixelOpera tion.SourceCopy ); [..]
I use this code to do something very similar to what you want to do. And it works.
Excellent... this works. Thank-you very much for the assistance.
I do have one question though when event is fired, the capture gets
the menuitem, from where the click occurs, in the image. Is there a
way to delay calling the capture function until the menuitem goes
away?
Thanks!
On Jun 11, 8:24 am, "Leo Seccia" <lsec...@msn.co mwrote:
I'm glad it worked.
You could try something like:
Application.DoE vents();
System.Threadin g.Thread.Sleep( 1000); //or less than a
second...
(But of course, that is a bit of a bodge... :-) )
Optionally, you might try to bring the panel to front or hide the menu item
before taking the screenshot...
Good luck to you. Let me know how you solve this one.
Leo, still haven't solved this one yet... perhaps I'll spend more time
on it this weekend. Thanks for the advice thus far! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Steffen Loringer |
last post by:
Hi group,
I like to print my ASP.NET page with the internet explorer. I added a
panel (with a black border and blue as background) and a button to my page.
If I press print in the Internet Explorer, the panel is printed without
the blue background but with the black border. The normal button is
printed as seen on screen.
What is the reason that the panel background color is not printed correctly?
|
by: DJ Pomeroy |
last post by:
I just can't seem to get it...
I have a form. On this form is a panel. In this panel is a bunch of
objects - graphics, text, and so on. I want to be able to print what's in
the panel to a printer. I'm not using Crystal Reports. Here's the code I
have so far...
Dim CurrPage As Integer
Dim LastPage As Integer
|
by: she_prog |
last post by:
Dear All,
I need to save the content of a panel to a bitmap. The panel can have
many child controls which also need to be saved. The problem would be
solved if I could have the panel saved to a Graphics object, which is
the same as if I'd need to print it. It'd be easy using
Control.DrawToBitmap, but I also need the invisible part of the panel
(which is hidden because of scrolling) and DrawToBitmap just takes a
screenshot.
|
by: dotnet2005 |
last post by:
Hi Toall ,
I want to explain you clearly ,
I am having some panels having some controls
CheckBox,ComboBox,Datagridview,Hyperlink,label,Listbox,Picturebox,RadioButt
on ,Textbox)
&(Oval,Line,Rectangle ). with .BorderStyle =
BorderStyle.FixedSingle . All these things are generating at runtime
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
| |
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |