11228 : How can I choose which printer to use?

Question

 

Using the print facilities of your object I can just launch the print preview based on the current default printer and its configurations (like paper size, etc).< ?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

 

I wonder how can do to let the user to select which printer to use and to properly configure it before printing the gantt.

 

Answer

 

Stole this more or less from MSDN:

public void Printing(string printer) {
 
try {
    streamToPrint =
new StreamReader (filePath);
   
try {
      printFont =
new Font(“Arial”, 10);
      PrintDocument pd =
new PrintDocument();
      pd.PrintPage +=
new PrintPageEventHandler(pd_PrintPage);
     
// Specify the printer to use.
      pd.PrinterSettings.PrinterName = printer;

      if (pd.PrinterSettings.IsValid) {
         pd.Print();
      }
     
else {   
         MessageBox.Show(
“Printer is invalid.”);
      }
    }
   
finally {
      streamToPrint.Close();
    }
  }
 
catch(Exception ex) {
    MessageBox.Show(ex.Message);
  }
}