WPF Reflections

Apr 24 2008   2:24PM GMT

WPF Printing – use the printing page



Posted by: MarkWPF
Tags:
printing
WPF

From a previous post of mine, you can see how to easily increase the size of a WPF element in order to print it.
That’s not much use though as you are still only hard coding the sizing.
What would be better is to use the height and width of the paper that has been selected.

Lo and behold, thats easy to do, using the PrintDialog class itself.
One further wrinkle is that you need to make sure that the actual element is resized, and you do that by telling it to resize itself.

Say you have an instance of PrintDialog called prtDlg:

Size pageSize = new Size(prtDlg.PrintableAreaWidth -30, prtDlg.PrintableAreaHeight – 30);
grd.Measure(pageSize);
grd.Arrange(new Rect(15, 15, pageSize.Width, pageSize.Height));

prtDlg.PrintVisual(grd, “My grid”);

Where grd is a Grid control containing a number of other elements

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: