PrintPageEventArgs.HasMorePages Propriété
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient ou définit une valeur indiquant si une autre page doit être imprimée.
public:
property bool HasMorePages { bool get(); void set(bool value); };
public bool HasMorePages { get; set; }
member this.HasMorePages : bool with get, set
Public Property HasMorePages As Boolean
Valeur de propriété
true si une autre page doit être imprimée, sinon, false. La valeur par défaut est false.
Exemples
L’exemple de code suivant suppose qu’un Button nommé printButton et un PrintDocument nommé pd ont été créés sur un Form. Vérifiez que l’événement Click pour le Button est associé à la printButton_Click méthode et que l’événement PrintPage de est PrintDocument associé à la pd_PrintPage méthode dans l’exemple. La printButton_Click méthode de l’exemple appelle la Print méthode qui déclenche l’événement PrintPage et imprime le fichier .bmp spécifié dans la pd_PrintPage méthode. Pour exécuter cet exemple, modifiez le chemin d’accès à la bitmap que vous souhaitez imprimer.
Utilisez les System.Drawingespaces de noms , System.Drawing.Printinget System.Windows.Forms pour cet exemple.
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
Pour un autre exemple qui montre comment utiliser HasMorePages, consultez Guide pratique pour imprimer un fichier texte multipage dans Windows Forms.