Freigeben über


PrintPageEventArgs.HasMorePages-Eigenschaft

Ruft einen Wert ab, der angibt, ob eine zusätzliche Seite gedruckt werden soll, oder legt diesen fest.

Namespace: System.Drawing.Printing
Assembly: System.Drawing (in system.drawing.dll)

Syntax

'Declaration
Public Property HasMorePages As Boolean
'Usage
Dim instance As PrintPageEventArgs
Dim value As Boolean

value = instance.HasMorePages

instance.HasMorePages = value
public bool HasMorePages { get; set; }
public:
property bool HasMorePages {
    bool get ();
    void set (bool value);
}
/** @property */
public boolean get_HasMorePages ()

/** @property */
public void set_HasMorePages (boolean value)
public function get HasMorePages () : boolean

public function set HasMorePages (value : boolean)

Eigenschaftenwert

true, wenn eine zusätzliche Seite gedruckt werden soll, andernfalls false. Der Standardwert ist false.

Beispiel

Im folgenden Codebeispiel wird davon ausgegangen, dass ein Button in einem Form erstellt wurde. Die printButton_Click-Methode aus dem Beispiel erstellt eine Instanz der PrintDocument-Klasse, ruft die pd_PrintPage-Methode auf und druckt die in der pd_PrintPage-Methode angegebene BMP-Datei. Um dieses Beispiel auszuführen, ändern Sie den Pfad der zu druckenden Bitmap.

Verwenden Sie für dieses Beispiel die Namespaces System.ComponentModel, System.Collections, System.Drawing, System.Drawing.Printing, System.Resources und System.Windows.Forms.

' 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
// 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;
 }
 
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;
   }
// 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

Plattformen

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

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

PrintPageEventArgs-Klasse
PrintPageEventArgs-Member
System.Drawing.Printing-Namespace