PageSettings.PaperSize 属性

获取或设置该页的纸张大小。

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

语法

声明
Public Property PaperSize As PaperSize
用法
Dim instance As PageSettings
Dim value As PaperSize

value = instance.PaperSize

instance.PaperSize = value
public PaperSize PaperSize { get; set; }
public:
property PaperSize^ PaperSize {
    PaperSize^ get ();
    void set (PaperSize^ value);
}
/** @property */
public PaperSize get_PaperSize ()

/** @property */
public void set_PaperSize (PaperSize value)
public function get PaperSize () : PaperSize

public function set PaperSize (value : PaperSize)

属性值

PaperSize,它表示纸张大小。默认值为打印机的默认纸张大小。

异常

异常类型 条件

InvalidPrinterException

PrinterSettings.PrinterName 属性中指定的打印机不存在或者没有已安装的默认打印机。

备注

PaperSize,通过 PaperSize.Kind 属性来表示纸张的大小,该属性包含一个 PaperKind 值。

将页面的 PaperSize 属性设置为有效的 PaperSize(可通过 PrinterSettings.PaperSizes 集合获得)。

有关如何指定自定义纸张大小的信息,请参见 PaperSize 构造函数。

示例

下面的代码示例设置文档的默认页的三个属性(包括根据 comboPaperSize 组合框中选定的大小确定的纸张大小),然后使用 Print 方法打印该文档。该示例要求名为 printDocPrintDocument 变量和特定的组合框都已存在。

Private Sub MyButtonPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyButtonPrint.Click

    ' Set the paper size based upon the selection in the combo box.
    If comboPaperSize.SelectedIndex <> -1 Then
        printDoc.DefaultPageSettings.PaperSize = _
        printDoc.PrinterSettings.PaperSizes.Item(comboPaperSize.SelectedIndex)
    End If

    ' Set the paper source based upon the selection in the combo box.
    If comboPaperSource.SelectedIndex <> -1 Then
        printDoc.DefaultPageSettings.PaperSource = _
        printDoc.PrinterSettings.PaperSources.Item(comboPaperSource.SelectedIndex)
    End If

    ' Set the printer resolution based upon the selection in the combo box.
    If comboPrintResolution.SelectedIndex <> -1 Then
        printDoc.DefaultPageSettings.PrinterResolution = _
        printDoc.PrinterSettings.PrinterResolutions.Item(comboPrintResolution.SelectedIndex)
    End If

    ' Print the document with the specified paper size and source.
    printDoc.Print()

End Sub
private void MyButtonPrint_Click(object sender, System.EventArgs e)
{
    // Set the paper size based upon the selection in the combo box.
    if (comboPaperSize.SelectedIndex != -1) {
        printDoc.DefaultPageSettings.PaperSize = 
            printDoc.PrinterSettings.PaperSizes[comboPaperSize.SelectedIndex];
    }

    // Set the paper source based upon the selection in the combo box.
    if (comboPaperSource.SelectedIndex != -1) {
        printDoc.DefaultPageSettings.PaperSource = 
            printDoc.PrinterSettings.PaperSources[comboPaperSource.SelectedIndex];
    }
    
    // Set the printer resolution based upon the selection in the combo box.
    if (comboPrintResolution.SelectedIndex != -1) 
    {
        printDoc.DefaultPageSettings.PrinterResolution= 
            printDoc.PrinterSettings.PrinterResolutions[comboPrintResolution.SelectedIndex];
    }

    // Print the document with the specified paper size, source, and print resolution.
    printDoc.Print();
}
private:
   void MyButtonPrint_Click( Object^ sender, System::EventArgs^ e )
   {
      // Set the paper size based upon the selection in the combo box.
      if ( comboPaperSize->SelectedIndex != -1 )
      {
         printDoc->DefaultPageSettings->PaperSize = printDoc->PrinterSettings->PaperSizes[ comboPaperSize->SelectedIndex ];
      }

      // Set the paper source based upon the selection in the combo box.
      if ( comboPaperSource->SelectedIndex != -1 )
      {
         printDoc->DefaultPageSettings->PaperSource = printDoc->PrinterSettings->PaperSources[ comboPaperSource->SelectedIndex ];
      }

      // Set the printer resolution based upon the selection in the combo box.
      if ( comboPrintResolution->SelectedIndex != -1 )
      {
         printDoc->DefaultPageSettings->PrinterResolution = printDoc->PrinterSettings->PrinterResolutions[ comboPrintResolution->SelectedIndex ];
      }

      // Print the document with the specified paper size, source, and print resolution.
      printDoc->Print();
   }
private void myButtonPrint_Click(Object sender, System.EventArgs e)
{
    // Set the paper size based upon the selection in the combo box.
    if (comboPaperSize.get_SelectedIndex() != -1) {
        printDoc.get_DefaultPageSettings().set_PaperSize(printDoc.
            get_PrinterSettings().get_PaperSizes().
            get_Item(comboPaperSize.get_SelectedIndex()));
    }
    // Set the paper source based upon the selection in the combo box.
    if (comboPaperSource.get_SelectedIndex() != -1) {
        printDoc.get_DefaultPageSettings().set_PaperSource(printDoc.
            get_PrinterSettings().get_PaperSources().
            get_Item(comboPaperSource.get_SelectedIndex()));
    }
    // Set the printer resolution based upon the selection in the combo box.
    if (comboPrintResolution.get_SelectedIndex() != -1) {
        printDoc.get_DefaultPageSettings().set_PrinterResolution(printDoc.
            get_PrinterSettings().get_PrinterResolutions().
            get_Item(comboPrintResolution.get_SelectedIndex()));
    }
    // Print the document with the specified paper size, source,
    // and print resolution.
    printDoc.Print();
} //myButtonPrint_Click

平台

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

请参见

参考

PageSettings 类
PageSettings 成员
System.Drawing.Printing 命名空间
PaperSize
PaperSize.Height
PaperSize.Kind
PaperSize.Width