PDA

Click to See Complete Forum and Search --> : MCL Form Print Component


Merrion
Feb 15th, 2007, 10:50 AM
One of the most common questions is "how can I print / print preview my form"? This is quite easily done by getting the form to "draw itself" on the printed page but this is often unsatisfactory because:
* The location of components on the form may not be where you want them on the printed page
* Text is drawn at screen resolution
* Every control is drawn (e.g. buttons, the form border etc.)

The attached component addresses the problem in a different manner.
What you do is drop a FormPrintHelperComponent component onto your form an it extends each control with a bunch of new properties (look in the properties window for each control in the section named "MCL Form Print Helper"). You then set these to indicate:
* Whether the control should be printed
* Whether to print it as Text, Image or Owner Drawn
* The boundary rectangle to print it in
* The vertical / horizontal alignment within that area
* Font and background/foreground colour to use etc.

You can then preview the result in design time (the component has a smart tag menu) and preview or print it at run time.

Additionally if you set the print mode for a control to be "owner drawn" the control will raise an event when the form is being printed to allow you to print the form however you feel ...

(This is an early release - I'm going to add the niceties of grid printing and multi-page printing etc. at a later release)

Merrion
May 8th, 2007, 01:15 PM
New release - now has a PageSetup and PrinterSettings method which brings up the respective dialog boxes to allow the user to view or change the page and printer settings at run time.

Merrion
Jun 13th, 2007, 01:00 PM
New release with multi page printing - basically you can decide at design time how many logical pages to turn your form into and then use the extended properties on each control to set which page(s) it prints on.

Options are:

Print on every page
Print on odd pages
print on even pages
print on selected pages - which in turn has an array of boolean that you set to True for the page you want to print the control on.

Merrion
Dec 7th, 2007, 05:09 PM
Oops - found a bug:

When you are printing an RTF box in RTF mode and you preview it more than once or preview then print it the RTF box doesn't print the second time. The fix is to change the RTFControlPrintSetting class thus:-

#Region "NewLogicalPage"
Public Overrides Sub NewLogicalPage()
If _RichTextBoxPrintMethod = RichTextBoxPrintMethods.PlainText Then
With Me.RichTextBoxControl
_CurrentLine = 0
_Lines = .Lines
_TotalLines = _Lines.Length
End With
Else
_CurrentChar = 0
_TotalChars = Me.RichTextBoxControl.TextLength
End If
End Sub
#End Region

Merrion
May 7th, 2008, 02:49 AM
A couple of video demos:

1. Adding a reference to the component (http://silverlight.services.live.com/invoke/65357/Add%20Reference%20To%20The%20MCL%20Form%20Print%20Helper%20component/iframe.html)

2. Setting the RTF print mode (http://silverlight.services.live.com/invoke/65357/Set%20RTFBox%20print%20mode/iframe.html)

3. Showing gridlines on preview to help layout controls (http://silverlight.services.live.com/invoke/65357/Show%20Gridlines%20On%20Preview/iframe.html)

Xancholy
Jun 17th, 2008, 03:18 PM
Outstanding Merrion. Now when are we going to be able to add custom header/footer to rtb contents ? Eagerly awaiting...

Xancholy
Jun 17th, 2008, 03:19 PM
Just a small not to say that Merrion's videos do not play on Firefox(yet). Use IE.

tom1859
Feb 6th, 2010, 01:53 PM
A link to it would be nice :)

Merrion
Feb 8th, 2010, 08:52 AM
Current version is always on CodePlex (http://mclformprint.codeplex.com/)...old version s have been removed as they just cause confusion.

tom1859
Feb 8th, 2010, 11:56 AM
Ok, thanks :)

tom1859
Feb 8th, 2010, 11:57 AM
Will i be able to use my own Print Preview form with this?

Thanks

Merrion
Feb 8th, 2010, 12:25 PM
Not out of the box, no.

You can change/extend the component yourself to customise the print preview screen if you wish

tom1859
Feb 8th, 2010, 12:40 PM
Thanks :), what language is the code, is it C++?

Merrion
Feb 8th, 2010, 04:22 PM
It is coded in VB.Net
(A C# version also exists on the same site)

tom1859
Feb 12th, 2010, 11:34 AM
Please will you send me an example of how to use this just to print a richtextbox and header and footer labels.

Thanks

Merrion
Feb 12th, 2010, 05:08 PM
There is this worked example of a rich text box (http://mclformprint.codeplex.com/wikipage?title=worked%20example%20simple%20form&referringTitle=Documentation)

Start with that then add a hidden label to yoru form for header and footer and add that to the set of controls being printed.

Bish-bash-bosh - job done

tom1859
Feb 13th, 2010, 06:23 AM
I give up on this control :(

Merrion
Feb 14th, 2010, 07:09 AM
Good to hear.

Anyone with more ambition should look into the updated documentation on the CodePlex documentation page (http://mclformprint.codeplex.com/documentation)

tom1859
Feb 14th, 2010, 09:22 AM
Sorry...,

Im checking that link out now :D