Click here to Skip to main content
13,045,019 members (42,534 online)
Rate this:
Please Sign up or sign in to vote.
See more:

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,

Maciej Los, you are correct I did not supply the language of choice.
I appreciate yours and Sergey's responses.
Posted 30-Apr-13 11:21am
Avi Farah8.8K
Updated 30-Apr-13 17:09pm
Sergey Alexandrovich Kryukov 30-Apr-13 17:26pm
What do you mean by this "shot". Perhaps, so called "screen shot"?
Rate this: bad
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:[^].

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:[^],[^],[^].

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.

Maciej Los 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 30-Apr-13 18:37pm
Thank you, Maciej.
Rate this: bad
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.

Print Form Component[^]
All about PrintForm component 1.0[^]
Using the PrintForm component in Visual Basic (Matt Gertz)[^]
Sergey Alexandrovich Kryukov 30-Apr-13 18:37pm
Sure, a 5.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 30 Apr 2013
Copyright © CodeProject, 1999-2017
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