Question : How do I control (set) printer properties programatically without the print dialog window?

I have an extensive and complicated print system based on GDI plus, I want to be able to control where the output of the application goes as it has to have the capacity to print to multiple printers as well as specifically define the printer tray (prints onto different pre-printed stock in separate trays depending on what is being printed).

Code snippet attached of what I am trying to achieve, unfortunately I can't find any built in properties or methods that allow me to specific which Tray to use.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
PrintDocument printDoc = new PrintDocument();
printDoc.PrinterSettings = new PrinterSettings();
printDoc.PrinterSettings.PrinterName = strPrinterName; //this works
printDoc.PrinterSettings.PaperSource = "Tray 1"; // this doesnt' exist but its basically what i need to do
printDoc.PrintPage += new PrintPageEventHandler(printDoc_PrintPage); //this calls method to draw onto Printjob
printDoc.Print();
 
//etc etc..

Answer : How do I control (set) printer properties programatically without the print dialog window?

As it turns out I have managed to find the solution on my own ;-)

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
PrintDocument printDoc = new PrintDocument();
PaperSize oPS = new PaperSize();
oPS.RawKind = (int)PaperKind.A4;
PaperSource oPSource = new PaperSource();
oPSource.RawKind = (int) PaperSourceKind.Upper;
 
printDoc.PrinterSettings = new PrinterSettings();
printDoc.PrinterSettings.PrinterName = sPrinterName;
printDoc.DefaultPageSettings.PaperSize = oPS;
printDoc.DefaultPageSettings.PaperSource = oPSource;
printDoc.PrintPage += new PrintPageEventHandler(printDoc_PrintPage);
printDoc.Print();
printDoc.Dispose();
Random Solutions  
 
programming4us programming4us