Export (0) Print
Expand All

PrintPageEventArgs Class

Provides data for the PrintPage event.

For a list of all members of this type, see PrintPageEventArgs Members.

System.Object
   System.EventArgs
      System.Drawing.Printing.PrintPageEventArgs

[Visual Basic]
Public Class PrintPageEventArgs
   Inherits EventArgs
[C#]
public class PrintPageEventArgs : EventArgs
[C++]
public __gc class PrintPageEventArgs : public EventArgs
[JScript]
public class PrintPageEventArgs extends EventArgs

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

MarginBounds retrieves the rectangular area that represents the portion of the page between the margins. PageBounds retrieves the rectangular area that represents the total area of the page. Graphics defines the graphics object with which to do the painting. PageSettings retrieves the printer settings for the current page. The remaining properties indicate whether a print job should be canceled or whether a print job has more pages.

For more information on printing, see the System.Drawing.Printing namespace overview.

Example

[Visual Basic, C#, C++] Use the System.ComponentModel, System.Collections, System.Drawing, System.Drawing.Printing, System.Resources, and System.Windows.Forms namespaces for this example.

[Visual Basic, C#, C++] The following example assumes a Button has been created on a Form. The printButton_Click method from the example creates an instance of PrintDocument, calls the pd_PrintPage method, and prints the .bmp file specified in the pd_PrintPage method. To run this example, change the path to the bitmap you want to print.

[Visual Basic] 
' Specifies what happens when the user clicks the Button.
Private Sub printButton_Click(sender As Object, e As EventArgs)
    Try
        ' Assumes the default printer.
        Dim pd As New PrintDocument()
        AddHandler pd.PrintPage, AddressOf Me.pd_PrintPage
        pd.Print()
    Catch ex As Exception
        MessageBox.Show("An error occurred while printing", _
            ex.ToString())
    End Try
End Sub    

' Specifies what happens when the PrintPage event is raised.
Private Sub pd_PrintPage(sender As Object, ev As PrintPageEventArgs)
    ' Draw a picture.
    ev.Graphics.DrawImage(Image.FromFile("C:\My Folder\MyFile.bmp"), _
        ev.Graphics.VisibleClipBounds)
    
    ' Indicate that this is the last page to print.
    ev.HasMorePages = False
End Sub


[C#] 
// Specifies what happens when the user clicks the Button.
 private void printButton_Click(object sender, EventArgs e) 
 {
   try 
   {
     // Assumes the default printer.
     PrintDocument pd = new PrintDocument();
     pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);
     pd.Print();
   }  
   catch(Exception ex) 
   {
     MessageBox.Show("An error occurred while printing", ex.ToString());
   }
 }
 
 // Specifies what happens when the PrintPage event is raised.
 private void pd_PrintPage(object sender, PrintPageEventArgs ev) 
 {      
   // Draw a picture.
   ev.Graphics.DrawImage(Image.FromFile("C:\\My Folder\\MyFile.bmp"), ev.Graphics.VisibleClipBounds);
      
   // Indicate that this is the last page to print.
   ev.HasMorePages = false;
 }
 

[C++] 
// Specifies what happens when the user clicks the Button.
private:
 void printButton_Click(Object* /*sender*/, EventArgs* /*e*/) 
 {
   try 
   {
     // Assumes the default printer.
     PrintDocument* pd = new PrintDocument();
     pd->PrintPage += new PrintPageEventHandler(this, &Form1::pd_PrintPage);
     pd->Print();
   }  
   catch(Exception* ex) 
   {
     MessageBox::Show(S"An error occurred while printing", ex->ToString());
   }
 }
 
 // Specifies what happens when the PrintPage event is raised.
private:
 void pd_PrintPage(Object* /*sender*/, PrintPageEventArgs* ev) 
 {      
   // Draw a picture.
   ev->Graphics->DrawImage(Image::FromFile(S"C:\\My Folder\\MyFile.bmp"), ev->Graphics->VisibleClipBounds);
      
   // Indicate that this is the last page to print.
   ev->HasMorePages = false;
 }
 

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Drawing.Printing

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System.Drawing (in System.Drawing.dll)

See Also

PrintPageEventArgs Members | System.Drawing.Printing Namespace | Graphics | Rectangle | PrintEventArgs

Show:
© 2014 Microsoft