views:

234

answers:

2

I have the following code to throw up a printer dialog box but no matter what printer I choose, it always prints to the default printer.

How do I assign the users selected printer? (from the dialog window)

PrintDialog pdlg = new PrintDialog();

// Show the PrintDialog
if (pdlg.ShowDialog() == DialogResult.OK)
{
   PrintDocument pd = new PrintDocument();
   pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);

   // Associate PrintDocument object with the PrintDialog
   pdlg.Document = pd;

   // Print with the new PrinterSettings
   pd.Print();
}
+2  A: 

I believe you need to use the PrinterSettings property from the PrintDialog instance and set the appropriate values in the PrintDocument instance you created.

In other words:

pd.PrinterSettings = pdlg.PrinterSettings;
Nick
Nope - didnt solve it
Matt Joslin
+3  A: 

You need to assign the PrintDocument to the PrintDialog before you call ShowDialog().

dar7yl
This did the trick - Many thanks!
Matt Joslin
You're welcome. This problem always bites me.
dar7yl