1

I am attempting to create a preview of a letter my program automatically prints nightly. I have read a few articles, but still am having trouble understanding.

I understand I need to create a PrintPreviewDialog object, which I can call ShowDialog() on, once I've supplied it with a PrintDocument. My main question is, how do I create a PrintDocument?

I have all the information for the letter saved in separate variables, so I'll have to combine all of them, which is easy enough, but how do I change that object (StringBuilder) into a PrintDocument I can provide to the PrintPreviewDialog object?

As always, thanks for any help!

OogaBooga
  • 479
  • 1
  • 5
  • 12

1 Answers1

0

The print logic you have to put it inside a PrintPage event handler of the PrintDocument.

You can read http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx . It contains a complete example.

Iraklis
  • 810
  • 5
  • 14
  • So I need to do ... pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage); ... for my PrintDocument (named pd), and instead of calling print, just pass it to the PrintPreviewDialog object? – OogaBooga Nov 28 '10 at 01:15
  • yes! PrintPreviewDialog1.Document = pd; PrintPreviewDialog1.ShowDialog(); – Iraklis Nov 28 '10 at 01:21