PrintPageEventArgs 类

PrintPage 事件提供数据。

**命名空间:**System.Drawing.Printing
**程序集:**System.Drawing(在 system.drawing.dll 中)

语法

声明
Public Class PrintPageEventArgs
    Inherits EventArgs
用法
Dim instance As PrintPageEventArgs
public class PrintPageEventArgs : EventArgs
public ref class PrintPageEventArgs : public EventArgs
public class PrintPageEventArgs extends EventArgs
public class PrintPageEventArgs extends EventArgs

备注

MarginBounds 属性检索表示边距之间的页面部分的矩形区域。PageBounds 属性检索表示整个页面区域的矩形区域。Graphics 属性定义要用来进行绘制的图形对象。PageSettings 属性检索当前页的打印机设置。剩余的属性指示是否应取消打印作业或打印作业是否有更多的页。

有关打印的更多信息,请参见 System.Drawing.Printing 命名空间概述。

示例

下面的代码示例假定已经在 Form 上创建了一个 Button。示例中的 printButton_Click 方法创建 PrintDocument 类的一个实例,调用 pd_PrintPage 方法,然后打印 pd_PrintPage 方法中指定的 .bmp 文件。若要运行该示例,请更改要打印的位图的路径。

System.ComponentModelSystem.CollectionsSystem.DrawingSystem.Drawing.PrintingSystem.ResourcesSystem.Windows.Forms 命名空间用于此示例。

' Specifies what happens when the user clicks the Button.
Private Sub printButton_Click(sender As Object, e As EventArgs)
    Try
        ' Assumes the default printer.
        Dim pd As New PrintDocument()
        AddHandler pd.PrintPage, AddressOf Me.pd_PrintPage
        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)
    ' 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
// Specifies what happens when the user clicks the Button.
 private void printButton_Click(object sender, EventArgs e) 
 {
   try 
   {
     // Assumes the default printer.
     PrintDocument pd = new PrintDocument();
     pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);
     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;
 }
 
private:
   // Specifies what happens when the user clicks the Button.
   void printButton_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
   {
      try
      {
         // Assumes the default printer.
         PrintDocument^ pd = gcnew PrintDocument;
         pd->PrintPage += gcnew PrintPageEventHandler( this, &Form1::pd_PrintPage );
         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.
        PrintDocument pd = new PrintDocument();
        pd.add_PrintPage(new PrintPageEventHandler(this.pd_PrintPage));
        pd.Print();
    }
    catch (System.Exception ex) {
        MessageBox.Show("An error occurred while printing", ex.ToString());
    }
} //printButton_Click

// Specifies what happens when the PrintPage event is raised.
private void pd_PrintPage(Object sender, PrintPageEventArgs ev)
{
    // Draw a picture.
    ev.get_Graphics().DrawImage(Image.FromFile
        ("C:\\My Folder\\MyFile.bmp"),
        ev.get_Graphics().get_VisibleClipBounds());

    // Indicate that this is the last page to print.
    ev.set_HasMorePages(false);
} //pd_PrintPage

继承层次结构

System.Object
   System.EventArgs
    System.Drawing.Printing.PrintPageEventArgs

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

PrintPageEventArgs 成员
System.Drawing.Printing 命名空间
Graphics 类
Rectangle 结构
PrintEventArgs 类