Monday, March 7, 2011

Sharing one PrintDocument instance

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

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

  • 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

0 comments:

Post a Comment