PrintPageEventArgs 类

定义

PrintPage 事件提供数据。Provides data for the PrintPage event.

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

示例

下面的代码示例假定已ButtonprintButtonPrintDocument pd创建了一个名为的和名为的。 FormThe following code example assumes a Button named printButton and a PrintDocument named pd have been created on a Form. Click确保pd_PrintPageButton事件printButton_Click 与该PrintDocument方法相关联, 并且的事件与示例中的方法相关联。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中的方法调用引发PrintPage事件Print的方法, 并pd_PrintPage打印方法中指定的 .bmp 文件。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

注解

MarginBounds属性检索表示边距之间页面部分的矩形区域。The MarginBounds property retrieves the rectangular area that represents the portion of the page between the margins. PageBounds属性检索表示页面总区域的矩形区域。The PageBounds property retrieves the rectangular area that represents the total area of the page. Graphics属性定义用于进行绘制的图形对象。The Graphics property defines the graphics object with which to do the painting. PageSettings属性检索当前页的打印机设置。The PageSettings property retrieves the printer settings for the current page. 其余属性指示是否应取消打印作业, 或者打印作业是否有更多页面。The remaining properties indicate whether a print job should be canceled or whether a print job has more pages.

有关 Windows 窗体打印的详细信息, 请参阅System.Drawing.Printing命名空间概述。For more information about printing with Windows Forms, see the System.Drawing.Printing namespace overview. 如果要从 Windows Presentation Foundation 应用程序进行打印, 请参阅System.Printing命名空间。If you wish to print from a Windows Presentation Foundation application, see the System.Printing namespace.

构造函数

PrintPageEventArgs(Graphics, Rectangle, Rectangle, PageSettings)

初始化 PrintPageEventArgs 类的新实例。Initializes a new instance of the PrintPageEventArgs class.

属性

Cancel

获取或设置一个值,该值指示是否取消打印作业。Gets or sets a value indicating whether the print job should be canceled.

Graphics

获取用于绘制页的 GraphicsGets the Graphics used to paint the page.

HasMorePages

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

MarginBounds

获取表示边距以内的页面部分的矩形区域。Gets the rectangular area that represents the portion of the page inside the margins.

PageBounds

获取表示页面全部区域的矩形区域。Gets the rectangular area that represents the total area of the page.

PageSettings

获取当前页的页设置。Gets the page settings for the current page.

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

适用于

另请参阅