I have checked with the "Let \Windows manage my default Printer" checkbox in Printer & Scanners setting, if I used the below code for printing my document, it is changing the default printer from Printer & Scanners setting.
- public void Print(string FileName, int pintprintqty)
- {
- if (string.IsNullOrWhiteSpace(FileName)) return; // Prevents execution of below statements if filename is not selected.
- PrintDocument pd = new PrintDocument();
- //Disable the printing document pop-up dialog shown during printing.
- PrintController printController = new StandardPrintController();
- pd.PrintController = printController;
- pd.PrinterSettings.PrinterName = cmbLabelPrinter.Text.ToString();
- pd.PrinterSettings.Copies = Convert.ToInt16(pintprintqty);
- pd.DefaultPageSettings.Landscape = false;
- pd.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
- pd.PrinterSettings.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
- pd.PrintPage += (sndr, args) =>
- {
- System.Drawing.Image i = System.Drawing.Image.FromFile(FileName);
- //Adjust the size of the image to the page to print the full image without loosing any part of the image.
- System.Drawing.Rectangle m = args.MarginBounds;
- //Logic below maintains Aspect Ratio.
- if ((double)i.Width / (double)i.Height > (double)m.Width / (double)m.Height) // image is wider
- {
- m.Height = (int)((double)i.Height / (double)i.Width * (double)m.Width);
- }
- else
- {
- m.Width = (int)((double)i.Width / (double)i.Height * (double)m.Height);
- }
- //Calculating optimal orientation.
- pd.DefaultPageSettings.Landscape = m.Width > m.Height;
- pd.DefaultPageSettings.Landscape = false; //New
- args.Graphics.DrawImage(i, m);
- };
- pd.Print();
- }
How to print the document without changing the default printer setting in "Let Windows manage my default Printer" checkbox checked mode?


Answers
Know the answer? Post it. Somebody with the same question will find it here.