PrintPageEventArgs.HasMorePages 属性

定义

获取或设置一个值,该值指示是否打印附加页。Gets or sets a value indicating whether an additional page should be printed.

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

属性值

Boolean

若应打印附加页,则为 true;否则为 falsetrue if an additional page should be printed; otherwise, false. 默认值为 falseThe default is false.

示例

下面的代码示例假定 Button printButton PrintDocument pd 已在上创建了一个名为的和名为的 FormThe following code example assumes a Button named printButton and a PrintDocument named pd have been created on a Form. 请确保 Click 的事件与该 Button 方法相关联 printButton_Click ,并且的事件与 PrintPage PrintDocument 示例中的方法相关联 pd_PrintPageMake 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. printButton_Click示例中的方法调用 Print 引发事件的方法 PrintPage ,并打印方法中指定的 .bmp 文件 pd_PrintPageThe 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. 若要运行此示例,请更改要打印的位图的路径。To run this example, change the path to the bitmap you want to print.

System.Drawing 此示例中使用、 System.Drawing.PrintingSystem.Windows.Forms 命名空间。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

有关演示如何使用的另一个示例 HasMorePages ,请参阅 如何:在 Windows 窗体中打印多页文本文件For another example that shows how to use HasMorePages, see How to: Print a Multi-Page Text File in Windows Forms

适用于