views:

195

answers:

2

In my WinForms app, data can be printed on many locations. Everytime the user wants to print, I create a new PrintDocument instance, which is used for the current print job and then disposed. Everything is working, but the Print dialog is always set back to the default printer and its default parameters. If another printer is selected, the user must choose it every time again and again.

Is it a common approach to create one global PrintDocument instance and share it for all printing jobs accross the application? Like this the last selected printer would be always used. Or are there any other ways?

Thank you, Petr

+5  A: 

Why don't you create one PrinterSettings instance and pass that to each PrintDocument that you create instead?

lc
A: 

You could use the singleton pattern for defining the PrinterSettings instance or a PrintDocument instance so that you would not have to pass the reference around.

See Singleton Pattern

benPearce