如何:在執行階段從 PrintDialog 擷取使用者輸入How to: Capture User Input from a PrintDialog at Run Time

雖然您可以設定與設計階段的列印相關的選項,您有時要在執行階段,因為使用者所做的選擇最有可能變更這些選項。While you can set options related to printing at design time, you will sometimes want to change these options at run time, most likely because of choices made by the user. 您可以擷取使用者輸入來列印文件使用PrintDialogPrintDocument元件。You can capture user input for printing a document using the PrintDialog and the PrintDocument components.

若要以程式設計方式變更列印選項To change print options programmatically

  1. 新增PrintDialogPrintDocument元件加入至表單。Add a PrintDialog and a PrintDocument component to your form.

  2. 設定Document屬性PrintDialogPrintDocument加入至表單。Set the Document property of the PrintDialog to the PrintDocument added to the form.

    PrintDialog1.Document = PrintDocument1  
    
    printDialog1.Document = PrintDocument1;  
    
    printDialog1->Document = PrintDocument1;  
    
  3. 顯示PrintDialog元件使用ShowDialog方法。Display the PrintDialog component by using the ShowDialog method.

    PrintDialog1.ShowDialog()  
    
    printDialog1.ShowDialog();  
    
    printDialog1->ShowDialog();  
    
  4. 使用者的列印選項,從對話方塊將會複製到PrinterSettings屬性PrintDocument元件。The user's printing choices from the dialog will be copied to the PrinterSettings property of the PrintDocument component.

請參閱See Also

如何:在 Windows Forms 中列印多頁文字檔How to: Print a Multi-Page Text File in Windows Forms
Windows Forms 列印支援Windows Forms Print Support