PrintPageEventArgs 類別

定義

提供 PrintPage 事件的資料。

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

範例

下列程式代碼範例假設 Button 已在 上建立具名 printButtonPrintDocument 具名 pdForm。 請確定 Click 的 事件 ButtonprintButton_Click 方法相關聯,且的 PrintPage 事件 PrintDocumentpd_PrintPage 範例中的 方法相關聯。 範例 printButton_Click 中的 方法會呼叫 Print 引發 PrintPage 事件的方法,並列印 方法中指定的 pd_PrintPage .bmp 檔案。 若要執行此範例,請將路徑變更為您要列印的點陣圖。

針對此範例, System.Drawing請使用、 System.Drawing.PrintingSystem.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

備註

注意

在 .NET 6 和更新版本中,只有 Windows 作業系統才支援包含此類型的 System.Drawing.Common 套件。 在跨平臺應用程式中使用此類型會導致編譯時間警告和運行時間例外狀況。 如需詳細資訊,請參閱 僅限 Windows 上支援的 System.Drawing.Common

屬性 MarginBounds 會擷取矩形區域,代表邊界之間的頁面部分。 屬性 PageBounds 會擷取代表頁面總區域的矩形區域。 屬性 Graphics 會定義要用來進行繪製的圖形物件。 屬性 PageSettings 會擷取目前頁面的印表機設定。 其餘屬性會指出列印作業是否應該取消,還是列印作業是否有更多頁面。

如需使用 Windows Forms 列印的詳細資訊,請參閱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)

適用於

另請參閱