Print dialogs let the user print documents, and these dialogs are supported with the PrintDialog class. Before displaying a Print dialog, you set the Document property of a PrintDialog object to a PrintDocument object, and the PrinterSettings property to a PrinterSettings object of the kind set by Page Setup dialogs.
When the dialog is closed, you can print the document by assigning the PrintDialog object's PrinterSettings property (which returns a PrinterSettings object as configured by the user, indicating the number of copies to print, the printer to use, and so on) to the PrinterSettings property of the PrintDocument object and use the PrintDocument object's Print method to actually print the document. Here's how that might look in code:
Private Sub MenuItem1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MenuItem1.Click PrintDialog1.Document = PrintDocument1 PrintDialog1.PrinterSettings = PrintDocument1.PrinterSettings PrintDialog1.AllowSomePages = True If PrintDialog1.ShowDialog = DialogResult.OK Then PrintDocument1.PrinterSettings = PrintDialog1.PrinterSettings PrintDocument1.Print() End If End Sub
You can see a Print dialog in Figure 9.7—this one comes from the Printing example on the CD-ROM.