Matt
Matt

Reputation: 3802

Printing problem in C# windows app - Always prints to default printer

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();
}

Upvotes: 1

Views: 3562

Answers (2)

dar7yl
dar7yl

Reputation: 3747

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

Upvotes: 7

Nick
Nick

Reputation: 5945

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;

Upvotes: 2

Related Questions