Biblioteca de clases de .NET Framework
PrintPageEventArgs (Clase)

Proporciona los datos del evento PrintPage.

Espacio de nombres: System.Drawing.Printing
Ensamblado: System.Drawing (en system.drawing.dll)

Sintaxis

Visual Basic (Declaración)
Public Class PrintPageEventArgs
    Inherits EventArgs
Visual Basic (Uso)
Dim instance As PrintPageEventArgs
C#
public class PrintPageEventArgs : EventArgs
C++
public ref class PrintPageEventArgs : public EventArgs
J#
public class PrintPageEventArgs extends EventArgs
JScript
public class PrintPageEventArgs extends EventArgs
Comentarios

La propiedad MarginBounds obtiene el área rectangular que representa la parte de la página comprendida entre los márgenes. La propiedad PageBounds recupera el área rectangular que representa el área total de la página. La propiedad Graphics define el objeto gráfico con el que se va a realizar el dibujo. La propiedad PageSettings recupera la configuración de impresora de la página actual. Las propiedades restantes indican si se debe cancelar un trabajo de impresión o si a éste le quedan más páginas por imprimir.

Para obtener más información acerca de la impresión, vea la información general relacionada con el espacio de nombres System.Drawing.Printing.

Ejemplo

En el siguiente ejemplo se supone que se ha creado un Button en un Form. El método printButton_Click del ejemplo crea una instancia de la clase PrintDocument, llama al método pd_PrintPage e imprime el archivo .bmp especificado en el método pd_PrintPage. Para ejecutar este ejemplo, hay que modificar la ruta de acceso al mapa de bits que se desea imprimir.

Se utilizan los espacios de nombres System.ComponentModel, System.Collections, System.Drawing, System.Drawing.Printing, System.Resources y System.Windows.Forms para este ejemplo.

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++
private:
   // Specifies what happens when the user clicks the Button.
   void printButton_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
   {
      try
      {
         // Assumes the default printer.
         PrintDocument^ pd = gcnew PrintDocument;
         pd->PrintPage += gcnew PrintPageEventHandler( this, &Form1::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.
   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;
   }
J#
// 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.add_PrintPage(new PrintPageEventHandler(this.pd_PrintPage));
        pd.Print();
    }
    catch (System.Exception ex) {
        MessageBox.Show("An error occurred while printing", ex.ToString());
    }
} //printButton_Click

// Specifies what happens when the PrintPage event is raised.
private void pd_PrintPage(Object sender, PrintPageEventArgs ev)
{
    // Draw a picture.
    ev.get_Graphics().DrawImage(Image.FromFile
        ("C:\\My Folder\\MyFile.bmp"),
        ev.get_Graphics().get_VisibleClipBounds());

    // Indicate that this is the last page to print.
    ev.set_HasMorePages(false);
} //pd_PrintPage
Jerarquía de herencia

System.Object
   System.EventArgs
    System.Drawing.Printing.PrintPageEventArgs
Seguridad para subprocesos

Los miembros estáticos públicos (Shared en Visual Basic) de este tipo son seguros para la ejecución de subprocesos. No se garantiza que los miembros de instancias sean seguros para la ejecución de subprocesos.
Plataformas

Windows 98, Windows 2000 SP4, Windows Millennium, Windows Server 2003, Windows XP Media Center, Windows XP Professional x64, Windows XP SP2, Windows XP Starter Edition

.NET Framework no admite todas las versiones de cada plataforma. Para obtener una lista de las versiones admitidas, vea Requisitos del sistema.

Información de versión

.NET Framework

Compatible con: 2.0, 1.1, 1.0
Vea también

Etiquetas :


Page view tracker