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. 既定値は、false です。The default is false.

次のコード例では、という名前の Button printButton と、にという名前のが PrintDocument pd 作成されていることを前提としてい Form ます。The 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_PrintPage れていることを確認してください。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. この printButton_Click 例のメソッドは、 Print イベントを発生させるメソッドを呼び出し、 PrintPage メソッドで指定された .bmp ファイルを出力し pd_PrintPage ます。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. この例を実行するには、印刷するビットマップのパスを変更します。To run this example, change the path to the bitmap you want to print.

この例では、、、およびの各名前空間を使用し System.Drawing System.Drawing.Printing System.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

適用対象