Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Forms screenshot
Folks,
 
We need a generic routine, preferably written in C#, that will generate a "form shot" of the forms in our application (Windows Form as well as WPF forms). This shot will be triggered by a user action (say a menu option) and will generate a shot of the form that is currently in focus. The shot should include in its image the form as is, including the data and other graphics artefacts. The shot will include the entire form, even if some of it is off the display. The shots will preferably be in a .pdf format.
 
Does anyone know of a good way to achieve this goal.
 
Many thanks,
Avi
 
Maciej Los, you are correct I did not supply the language of choice.
I appreciate yours and Sergey's responses.
Posted 30-Apr-13 12:21pm
Avi Farah7.3K
Edited 30-Apr-13 18:09pm
v2
Comments
Sergey Alexandrovich Kryukov at 30-Apr-13 17:26pm
   
What do you mean by this "shot". Perhaps, so called "screen shot"?
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Please see my question. I will assume you need a screen shot.
 
First of all, you need to put the form on top, to see it all. If you want, you can easily remember the current Z-order and restore it later, using raw Windows API (do I even need to explain how? just look at the window functions; unfortunately, you have to use P/Invoke). I don't know if you can do it without showing the whole form and suspect it's impossible. The method requires the whole form to be shown on screen.
 
You just find out the form size and location in screen coordinates, and use System.Drawing.Graphics.CopyFromScreen for an instance of System.Drawing.Graphics taken from a newly created instance of System.Drawing.Bitmap. You can find some code sample here:
http://pcsxcetrasupport3.wordpress.com/2012/03/09/windows-form-screenshot-and-print-preview-in-vb-net/[^].
 
Using PDF for such things is not a good idea (even if you create it for documentation, you can do it later), but you always can make PDF from image if you use, for example, iText, more exactly, its .NET port, iTextSharp:
http://en.wikipedia.org/wiki/IText[^],
http://itextpdf.com/[^],
http://sourceforge.net/projects/itextsharp/[^].
 
In included the reference to Java iText site as well, because most documentation is there. If you understand C#, it would not be difficult to understand Java-bases API documentation.
 
—SA
  Permalink  
Comments
Maciej Los at 30-Apr-13 18:32pm
   
My 5!
Please, see my answer. I think OP wants to print "an image of form" to pdf and there is a class which provides method to print form with all controls and data in it.
Sergey Alexandrovich Kryukov at 30-Apr-13 18:37pm
   
Thank you, Maciej.
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

First of all, read solution1 by Sergey Alexandrovich Kryukov... There you'll find many useful information...
 
Secondly, you did not provide enough information to put exact answer (especially programming language), so i can only guess what you are looking for.
 
Please, see PrintForm Class[^], which enables printing an image of a Windows Form at run time.
 
More:
Print Form Component[^]
All about PrintForm component 1.0[^]
Using the PrintForm component in Visual Basic (Matt Gertz)[^]
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 30-Apr-13 18:37pm
   
Sure, a 5.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 30 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100