How to customize PrintPreviewDialog using C#



How to customize PrintPreviewDialog, such that, addition of a new button, change the functionality of existing button should be possible programatically. Sample code will help a lot. Moreover, what happens before the document gets displayed in PrintPreviewDialog, i.e. whether entire document gets copied in printer driver spool or only 1 or 2 pages?
please guide

Trent Millar


As for code you're on your own, and as for a better answer I'm not sure but since the PrintPreviewDialog uses a PrintPreview Control and since this PrintPreview control exposes all the properties the PrintPreviewDialog gives you such as setting the count of pages to display in the preview, or zoom factor... you can create your own PrintPreviewDialog without much effort.

here's a code sample using the PrintPreviewDialog,

previewDialog.PrintPreviewControl.StartPage = 0; // set which page the preview shows
previewDialog.PrintPreviewControl.Zoom = 1.0; // your previews zoom factor
previewDialog.PrintPreviewControl.Columns = 2; //Sets the page count to display within the preview

now if you created a new windows form and dragged a PrintPreviewControl onto it, set this controls Modifier property to 'internal protected' or higher you can access these properties when you instantiate the form from the main form. Now even dragging a toolbar into this new form you can mockup the original design of the PrintPreviewDialog. You're pretty much done short of adding your buttons, and when you add your buttons you might consider giving their DialogResult property a DialogResult value {OK, Cancel,Yes, No, Retry,Ignore,...} this way you can call the ShowDialog method on this new form to display the modally (Top-most and in control) then you can as well check the user's button press action by checking the returned DialogResult property.


MyPrintPreview printForm = new MyPrintPreview ();
printForm.PrintPreviewControl.Document = printDocument1; // Don't forget the you must attach a PrintDocument object to your Control!!!!
printForm.PrintPreviewControl.StartPage = 0;
printForm.PrintPreviewControl.Zoom = 1.0;
printForm.PrintPreviewControl.Columns = 2;

if (DialogResult.OK == printForm.ShowDialog())

Two thing's I'm sure you have probably done, is to make sure you have a PrintDocument object on the form and created the PrintPage event handler with the logic to actually compose your printed output. Without these you'll see nothing but grey or white depending on which of the two you have not done.



Thanks for your valuable suggestions Sir
I will definitely follow your instructions. In case of any difficulty, may I trouble you again



I tried the way you suggested but, the document instead of getting displayed in PrintPreviewControl, directly getting copied in printer spool and nothing is displayed in the Preview.
More over copying to spool becomes very slow.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question