I have the following code to show printer dialog box but no matter what printer I choose, it always prints to the default printer.
PrintDialog pdlg = new PrintDialog();
// Show the PrintDialog
if (pdlg.ShowDialog() == DialogResult.OK)
{
PrintDocument pd = new PrintDocument();
// Associate PrintDocument object with the PrintDialog
pdlg.Document = pd;
pd.PrinterSettings = pdlg.PrinterSettings;
pd.Print();
}
Solution:
Just Swapped Document and Printer Settings as below, and it worked for me.
PrintDialog pdlg = new PrintDialog();
// Show the PrintDialog
if (pdlg.ShowDialog() == DialogResult.OK)
{
PrintDocument pd = new PrintDocument();
pd.PrinterSettings = pdlg.PrinterSettings;
// Associate PrintDocument object with the PrintDialog
pdlg.Document = pd;
pd.Print();
}
Reference: Muthukumar (http://nadarmuthukumar.blogspot.in)



0 comments:
Post a Comment