Sharing a single PrintDocument instance

In my WinForms application, data can be printed in many places. Every time the user wants to print, I create a new PrintDocument instance that is used for the current print job and then deleted. Everything works, but the print dialog always reverts to the default printer and its default settings. If a different printer is selected, the user must select it over and over again each time.

Is it a common approach to create one global PrintDocument instance and share it across all print jobs throughout the application? Thus, the last selected printer will always be used. Or are there other ways?

Thanks, Petr

+1


source to share


2 answers


Why don't you create one instance PrinterSettings

and pass that for each PrintDocument

one you create instead?



+5


source


You can use the singleton pattern to define a PrinterSettings instance or PrintDocument instance so that you don't have to pass the link around.



See Singleton Pattern

0


source







All Articles