Something quick. I am trying to print many pages to a printer which is not the default printer.

Here's the code called when the user clicks Print:

Code:
        private void GeneratePrint()
        {
            PrintDocument document = new PrintDocument();
            document.BeginPrint += new PrintEventHandler(this.printDocument1_BeginPrint);
            document.QueryPageSettings += new QueryPageSettingsEventHandler(document_QueryPageSettings);
            document.PrintPage += new PrintPageEventHandler(this.printDocument1_PrintPage);
            document.DefaultPageSettings = this.pgSettings;
            this.printDialog1.Document = document;
            this.printDialog1.AllowSomePages = true;
            if (this.printDialog1.ShowDialog() == DialogResult.OK)
            {
                document.PrinterSettings = this.printDialog1.PrinterSettings;
                document.Print();
                return;
                //Other code not relevant
            }
        }
The event handlers for BeginPrint and PrintPage are as follows (QueryPrintSettings handler is empty)

Code:
        private void printDocument1_BeginPrint(object sender, PrintEventArgs e)
        {
            this.LoadLayoutData();

            PrinterSettings pSettings = ((PrintDocument)sender).PrinterSettings;
            //Some other code
        }
Here's the PrintPage:

Code:
        private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
        {
            //Prepares data for printing this page
            if (pageData[0].IsTopSheet == "True")
            {
                //this.printDocument1.DefaultPageSettings.PaperSource = this.GetPaperSourceForPrinter(this.printDocument1.DefaultPageSettings.PrinterSettings.PrinterName, "Top Sheet");
                e.PageSettings.PaperSource = this.GetPaperSourceForPrinter(e.PageSettings.PrinterSettings.PrinterName, "Top Sheet");
                this.GeneratePrintOutput(e.Graphics, e.PageSettings, pageData, this.TopsheetLayoutSettings, nudgeLeft, nudgeTop);
            }
            else if (pageData[0].IsBottomSheet == "True")
            {
                //this.printDocument1.DefaultPageSettings.PaperSource = this.GetPaperSourceForPrinter(this.printDocument1.DefaultPageSettings.PrinterSettings.PrinterName, "Bottom Sheet");
                e.PageSettings.PaperSource = this.GetPaperSourceForPrinter(e.PageSettings.PrinterSettings.PrinterName, "Bottom Sheet");
            }
            else
            {
                //this.printDocument1.DefaultPageSettings.PaperSource = this.GetPaperSourceForPrinter(this.printDocument1.DefaultPageSettings.PrinterSettings.PrinterName, pageData[0].CommodityCode);
                e.PageSettings.PaperSource = this.GetPaperSourceForPrinter(e.PageSettings.PrinterSettings.PrinterName, pageData[0].CommodityCode);
                this.GeneratePrintOutput(e.Graphics, e.PageSettings, pageData, this.VoucherLayoutSettings, nudgeLeft, nudgeTop);
            }
            this.currentPage++;
            e.HasMorePages = this.currentPage <= e.PageSettings.PrinterSettings.ToPage; // this.TotalPages;
        }
Now the default printer on my machine is an HP model. Since I am testing out the code, I want to print to a non-default printer, which is "CutePDF". I don't want to make this the default printer.

On clicking Print, the print dialog opens fine, and I am able to select CutePDF printer and set other settings. When I click Print from the print dialog, the BeginPrint and the PrintPage events fire in the correct order. When I check the BeginPrint event arguments, the "sender" property correctly points to the CutePDF printer. When I check the PrintPage event arguments, the "sender" property again correctly points to the CutePDF printer, but the "PrintEventArgs e" property still refers to the default HP printer. I am worried this will mess up my printing since I am trying to do some precision printing here, and printer settings would be important.

Why is this happening and how can this be rectified?

Thanks in advance.

.