ערוך

שתף באמצעות


PrintPageEventArgs Class

Definition

Provides data for the PrintPage event.

public ref class PrintPageEventArgs : EventArgs
public class PrintPageEventArgs : EventArgs
type PrintPageEventArgs = class
    inherit EventArgs
Public Class PrintPageEventArgs
Inherits EventArgs
Inheritance
PrintPageEventArgs

Examples

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.

Use the System.Drawing, System.Drawing.Printing, and System.Windows.Forms namespaces for this example.

private:
   // Specifies what happens when the user clicks the Button.
   void printButton_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
   {
      try
      {
         pd->Print();
      }
      catch ( Exception^ ex ) 
      {
         MessageBox::Show( "An error occurred while printing", ex->ToString() );
      }
   }

   // Specifies what happens when the PrintPage event is raised.
   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;
   }

// Specifies what happens when the user clicks the Button.
 private void printButton_Click(object sender, EventArgs e) 
 {
   try 
   {
     // Assumes the default printer.
     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;
 }
' 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

Remarks

Note

In .NET 6 and later versions, the System.Drawing.Common package, which includes this type, is only supported on Windows operating systems. Use of this type in cross-platform apps causes compile-time warnings and run-time exceptions. For more information, see System.Drawing.Common only supported on Windows.

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.

Constructors

PrintPageEventArgs(Graphics, Rectangle, Rectangle, PageSettings)

Initializes a new instance of the PrintPageEventArgs class.

Properties

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.

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(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)

Applies to

See also