I have a scroll-able form which I would like to print entirely.
I have already tried using this code to print it:
Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
Me.PrintForm.PrintAction = Printing.PrintAction.PrintToPreview
Me.PrintForm.Print(Me, PowerPacks.Printing.PrintForm.PrintOption.Scrollable)
End Sub
And the result isn't accurate at all.
To demonstrate my issue, here are some photos:
This is the result I want (Of course I want it to ALSO print all of the scroll-able content)
As you can see, This image contains all of the width I need for the image, but because it's a print screen image, it doesn't contain the scroll-able area which I would like to have in my printable version of the form.
and this is what I get from my code:
As you can see here, I only get about 60% of the form width, and 50% of the height, and clearly, I don't get the scroll-able area.
I don't really care about the quality I just want it to print the whole form including the Scroll-able area.
Check for the MSDN Forum of the code here the code like this
In the Toolbox, click the Visual Basic PowerPacks tab and then drag the PrintForm component onto the form.
The PrintForm component will be added to the component tray.
In the Properties window, set the PrintAction property to PrintToPrinter.
Add the following code in the appropriate event handler (for example, in the Click event handler for a Print Button).
and here got the same question as your and have been answer.
I Think your answer is in the article
All you need is to reference to FormPrinting library (or import the source to your solution).
will do the printing job.
I have tested the library, having no problems with scrollable contents like images and ....
I had a similar problem I was able to solve without any additional libraries or extensions. It is simple with the DrawToBitmap method available on most Forms controls.
In this line:
It looks like
PrintOption.Scrollable
is only going to work, if you have a scrollable form. You have a scrollable control here (probably aPanel
), inside a form. In this case its area will not be expanded onto the printer. Compare:Scrollable control:
prints as:
Scrollable form:
prints as:
According to this official answer from Microsoft, capturing a scrollable control is not possible with
PrintForm
. If you use a PrintDocument and some custom coding, you can do it for simple cases, such as a scrollable TextBox. In your case you may need even more custom coding to be done. HandlingPrintDocument1.PrintPage
looks like the best place to start, if you are up to it.Based on what you're showing... it looks like the scrollable area is a container like a Panel. If that's the case, printing the form isn't the problem, it's printing the scrollable control.
Have a look at this project to create a bitmap from a control: http://www.codeproject.com/Articles/35734/Print-a-WinForms-User-Control
EDIT: On second thought, I don't think the code at that link addresses the actual scrolling problem either.
I think you're going to need to do one of two things: 1) Temporarily resize the panel large enough that the scrollbars disappear then resize it back 2) Build a control (perhaps a "Printable Version" form) that doesn't have nested scrollable elements and gracefully deals with stuff like pagination.
Option #2 might sound like a lot of work, but I think you could pretty quickly do something like: create a new panel, clone each control you want printed and add it to the panel (resizing as necessary to avoid scrolling), print the panel, then dispose of the panel.