PrintPageEventArgs.HasMorePages Egenskap

Definition

Hämtar eller anger ett värde som anger om en ytterligare sida ska skrivas ut.

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

Egenskapsvärde

trueom ytterligare en sida ska skrivas ut; annars . false Standardvärdet är false.

Exempel

I följande kodexempel förutsätts att ett Button namngivet printButton och ett PrintDocument namngivet pd har skapats på en Form. Kontrollera att Click händelsen för Button är associerad med printButton_Click metoden och PrintPage att händelsen PrintDocument är associerad med pd_PrintPage metoden i exemplet. Metoden printButton_Click i exemplet anropar metoden Print som höjer PrintPage händelsen och skriver ut den .bmp fil som anges i pd_PrintPage metoden. Om du vill köra det här exemplet ändrar du sökvägen till den bitmapp som du vill skriva ut.

Använd namnrymderna System.Drawing, System.Drawing.Printing och System.Windows.Forms för det här exemplet.

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

Ett annat exempel som visar hur du använder HasMorePages finns i How to: Print a Multi-Page Text File in Windows Forms.

Gäller för

Se även