To view pages using the PrintPreviewDialog control
Use the ShowDialog method to display the dialog box, specifying the PrintDocument to use.
In the following code example, the Button control's Click event handler opens an instance of the PrintPreviewDialog control. The print document is specified in the Document property. In the example below, no print document is specified.
The example requires that your form has a Button control, a PrintDocument component named myDocument, and a PrintPreviewDialog control.
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
' The print document 'myDocument' used below
' is merely for an example.
' You will have to specify your own print document.
PrintPreviewDialog1.Document = myDocument
PrintPreviewDialog1.ShowDialog()
End Sub
private void button1_Click(object sender, System.EventArgs e)
{
// The print document 'myDocument' used below
// is merely for an example.
// You will have to specify your own print document.
printPreviewDialog1.Document = myDocument;
printPreviewDialog1.ShowDialog();
}
private void button1_Click(Object sender, System.EventArgs e)
{
// The print document 'myDocument' used below
// is merely for an example.
// You will have to specify your own print document.
printPreviewDialog1.set_Document(myDocument);
printPreviewDialog1.ShowDialog();
}
private:
void button1_Click(System::Object ^ sender,
System::EventArgs ^ e)
{
// The print document 'myDocument' used below
// is merely for an example.
// You will have to specify your own print document.
printPreviewDialog1->Document = myDocument;
printPreviewDialog1->ShowDialog();
}
(Visual C#, Visual C++) Place the following code in the form's constructor to register the event handler.
this.button1.Click += new System.EventHandler(this.button1_Click);
this->button1->Click += gcnew
System::EventHandler(this, &Form1::button1_Click);

See Also