PrintPageEventArgs Classe
Definizione
public ref class PrintPageEventArgs : EventArgs
public class PrintPageEventArgs : EventArgs
type PrintPageEventArgs = class
inherit EventArgs
Public Class PrintPageEventArgs
Inherits EventArgs
- Ereditarietà
Esempi
Nell'esempio di codice seguente si Button presuppone printButton
che un oggetto pd
denominato e un oggetto PrintDocument denominato Formsiano stati creati in un oggetto.The following code example assumes a Button named printButton
and a PrintDocument named pd
have been created on a Form. Verificare che l' Click evento Button per sia associato printButton_Click
al metodo e che pd_PrintPage
l' PrintPage evento di PrintDocument sia associato al metodo nell'esempio.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. Il printButton_Click
metodo dell'esempio chiama il Print metodo che genera l' PrintPage evento e pd_PrintPage
stampa il file con estensione bmp specificato nel metodo.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. Per eseguire questo esempio, modificare il percorso della bitmap che si desidera stampare.To run this example, change the path to the bitmap you want to print.
Usare gli System.Drawingspazi System.Drawing.Printingdei nomi System.Windows.Forms , e per questo esempio.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
Commenti
La MarginBounds proprietà recupera l'area rettangolare che rappresenta la parte della pagina tra i margini.The MarginBounds property retrieves the rectangular area that represents the portion of the page between the margins. La PageBounds proprietà recupera l'area rettangolare che rappresenta l'area totale della pagina.The PageBounds property retrieves the rectangular area that represents the total area of the page. La Graphics proprietà definisce l'oggetto Graphics con cui eseguire il disegno.The Graphics property defines the graphics object with which to do the painting. La PageSettings proprietà recupera le impostazioni della stampante per la pagina corrente.The PageSettings property retrieves the printer settings for the current page. Le proprietà rimanenti indicano se un processo di stampa deve essere annullato o se un processo di stampa contiene più pagine.The remaining properties indicate whether a print job should be canceled or whether a print job has more pages.
Per ulteriori informazioni sulla stampa con Windows Forms, vedere System.Drawing.Printing Cenni preliminari sullo spazio dei nomi.For more information about printing with Windows Forms, see the System.Drawing.Printing namespace overview. Se si desidera stampare da un'applicazione Windows Presentation Foundation, vedere lo System.Printing spazio dei nomi.If you wish to print from a Windows Presentation Foundation application, see the System.Printing namespace.
Costruttori
PrintPageEventArgs(Graphics, Rectangle, Rectangle, PageSettings) |
Inizializza una nuova istanza della classe PrintPageEventArgs.Initializes a new instance of the PrintPageEventArgs class. |
Proprietà
Cancel |
Ottiene o imposta un valore che indica se il processo di stampa deve essere annullato.Gets or sets a value indicating whether the print job should be canceled. |
Graphics |
Ottiene l’oggetto Graphics utilizzato per disegnare la pagina.Gets the Graphics used to paint the page. |
HasMorePages |
Ottiene o imposta un valore che indica se deve essere stampata una pagina aggiuntiva.Gets or sets a value indicating whether an additional page should be printed. |
MarginBounds |
Ottiene l'area rettangolare che rappresenta la parte della pagina all'interno dei margini.Gets the rectangular area that represents the portion of the page inside the margins. |
PageBounds |
Ottiene l'area rettangolare che rappresenta l'area totale della pagina.Gets the rectangular area that represents the total area of the page. |
PageSettings |
Ottiene le impostazioni di pagina per la pagina corrente.Gets the page settings for the current page. |
Metodi
Equals(Object) |
Determina se l'oggetto specificato è uguale all'oggetto corrente.Determines whether the specified object is equal to the current object. (Ereditato da Object) |
GetHashCode() |
Funge da funzione hash predefinita.Serves as the default hash function. (Ereditato da Object) |
GetType() |
Ottiene l'oggetto Type dell'istanza corrente.Gets the Type of the current instance. (Ereditato da Object) |
MemberwiseClone() |
Crea una copia superficiale dell'oggetto Object corrente.Creates a shallow copy of the current Object. (Ereditato da Object) |
ToString() |
Restituisce una stringa che rappresenta l'oggetto corrente.Returns a string that represents the current object. (Ereditato da Object) |