432 Part III Designing the User Interface
Your form looks like this:
- Double-click the Page Setup button (btnSetup) to display the btnSetup_Click event
procedure in the Code Editor. - Type the following program code:
Try
'Load page settings and display page setup dialog box
PageSetupDialog1.PageSettings = PrintPageSettings
PageSetupDialog1.ShowDialog()
Catch ex As Exception
'Display error message
MessageBox.Show(ex.Message)
End Try
The code for creating a Page Setup dialog box in this program is quite simple because
the PrintPageSettings variable has already been defined at the top of the form. This
variable holds the current page definition information, and when it’s assigned to
the PageSettings property of the PageSetupDialog1 object, the ShowDialog method
automatically loads a dialog box that allows the user to modify what the program has
selected as the default page orientation, margins, and so on. The Try... Catch error
handler simply handles any errors that might occur when the ShowDialog method is used.
- Display the form again, and then double-click the Print Preview button (btnPreview)
to display the btnPreview_Click event procedure.