PrintPageEventArgs クラス

定義

PrintPage イベントのデータを提供します。

public ref class PrintPageEventArgs : EventArgs
public class PrintPageEventArgs : EventArgs
type PrintPageEventArgs = class
    inherit EventArgs
Public Class PrintPageEventArgs
Inherits EventArgs
継承
PrintPageEventArgs

次のコード例では、Button名前付き と というprintButton名前pdの が PrintDocumentForm作成されていることを前提としています。 のClickイベントButtonが メソッドに関連付printButton_Clickけられていることを確認し、 のPrintPagePrintDocumentイベントが例の メソッドに関連付pd_PrintPageけられていることを確認します。 この例の メソッドは printButton_Click 、 イベントを Print 発生させるメソッドを PrintPage 呼び出し、 メソッドで指定された.bmp ファイルを pd_PrintPage 出力します。 この例を実行するには、印刷するビットマップへのパスを変更します。

この例では、 System.DrawingSystem.Drawing.Printing、および System.Windows.Forms 名前空間を使用します。

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

注釈

Note

.NET 6 以降のバージョンでは、この種類を含む System.Drawing.Common パッケージは Windows オペレーティング システムでのみサポートされています。 クロスプラットフォーム アプリでこの型を使用すると、コンパイル時の警告と実行時例外が発生します。 詳細については、「 Windows でのみサポートされる System.Drawing.Common」を参照してください。

プロパティは MarginBounds 、余白の間のページの部分を表す四角形の領域を取得します。 プロパティは PageBounds 、ページの合計領域を表す四角形の領域を取得します。 プロパティは Graphics 、描画を実行するグラフィックス オブジェクトを定義します。 プロパティは PageSettings 、現在のページのプリンター設定を取得します。 残りのプロパティは、印刷ジョブを取り消す必要があるかどうか、または印刷ジョブのページ数が多いかを示します。

Windows フォームを使用した印刷の詳細については、名前空間の概要に関するページをSystem.Drawing.Printing参照してください。 Windows Presentation Foundation アプリケーションから印刷する場合は、 名前空間をSystem.Printing参照してください。

コンストラクター

PrintPageEventArgs(Graphics, Rectangle, Rectangle, PageSettings)

PrintPageEventArgs クラスの新しいインスタンスを初期化します。

プロパティ

Cancel

印刷ジョブをキャンセルするかどうかを示す値を取得または設定します。

Graphics

ページの描画に使用される Graphics を取得します。

HasMorePages

追加のページを印刷するかどうかを示す値を取得または設定します。

MarginBounds

ページ余白の内側の部分を表す四角形領域を取得します。

PageBounds

ページの全領域を表す四角形領域を取得します。

PageSettings

現在のページのページ設定を取得します。

メソッド

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

適用対象

こちらもご覧ください