Partager via


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. You can capture user input for printing a document using the PrintDialog and the PrintDocument components.

To change print options programmatically

  1. Add a PrintDialog and a PrintDocument component to your form.

  2. Set the Document property of the PrintDialog to the PrintDocument added to the form.

    PrintDialog1.Document = PrintDocument1
    
    printDialog1.Document = PrintDocument1;
    
    printDialog1.Document = PrintDocument1;
    
    printDialog1->Document = PrintDocument1;
    
  3. Display the PrintDialog component by using the ShowDialog method.

    PrintDialog1.ShowDialog()
    
    printDialog1.ShowDialog();
    
    printDialog1.ShowDialog();
    
    printDialog1->ShowDialog();
    
  4. The user's printing choices from the dialog will be copied to the PrinterSettings property of the PrintDocument component.

See Also

Tasks

How to: Print a Multi-Page Text File in Windows Forms

Other Resources

Windows Forms Print Support