Provides data for the PrintPage event.
Assembly: System.Drawing (in System.Drawing.dll)
Thetype exposes the following members.
|Cancel||Gets or sets a value indicating whether the print job should be canceled.|
|Graphics||Gets the Graphics used to paint the page.|
|HasMorePages||Gets or sets a value indicating whether an additional page should be printed.|
|MarginBounds||Gets the rectangular area that represents the portion of the page inside the margins.|
|PageBounds||Gets the rectangular area that represents the total area of the page.|
|PageSettings||Gets the page settings for the current page.|
|Equals(Object)||Determines whether the specified object is equal to the current object. (Inherited from Object.)|
|Finalize||Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)|
|GetHashCode||Serves as the default hash function. (Inherited from Object.)|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|MemberwiseClone||Creates a shallow copy of the current Object. (Inherited from Object.)|
|ToString||Returns a string that represents the current object. (Inherited from Object.)|
The MarginBounds property retrieves the rectangular area that represents the portion of the page between the margins. The PageBounds property retrieves the rectangular area that represents the total area of the page. The Graphics property defines the graphics object with which to do the painting. The PageSettings property 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 about printing with Windows Forms, see the System.Drawing.Printing namespace overview. If you wish to print from a Windows Presentation Foundation application, see the System.Printing namespace.
The following code example assumes a Button named printButton and a PrintDocument named pd have been created on a Form. Make sure the Click event for the Button is associated with the printButton_Click method and the PrintPage event of the PrintDocument is associated with the pd_PrintPage method in the example. The printButton_Click method from the example calls the Print method raising the PrintPage event, 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.
' Specifies what happens when the user clicks the Button. Private Sub printButton_Click(sender As Object, e As EventArgs) _ Handles printButton.Click Try 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) _ Handles pd.PrintPage ' 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