Share via


PaperSize 构造函数

定义

初始化 PaperSize 类的新实例。

重载

PaperSize()

初始化 PaperSize 类的新实例。

PaperSize(String, Int32, Int32)

初始化 PaperSize 类的新实例。

注解

下表显示 PaperSize 类的实例的初始属性值。

属性 初始值
Kind PaperKind.Custom
PaperName String.Empty

PaperSize()

Source:
PaperSize.cs
Source:
PaperSize.cs
Source:
PaperSize.cs

初始化 PaperSize 类的新实例。

public:
 PaperSize();
public PaperSize ();
Public Sub New ()

适用于

PaperSize(String, Int32, Int32)

Source:
PaperSize.cs
Source:
PaperSize.cs
Source:
PaperSize.cs

初始化 PaperSize 类的新实例。

public:
 PaperSize(System::String ^ name, int width, int height);
public PaperSize (string name, int width, int height);
new System.Drawing.Printing.PaperSize : string * int * int -> System.Drawing.Printing.PaperSize
Public Sub New (name As String, width As Integer, height As Integer)

参数

name
String

纸张名称。

width
Int32

纸张宽度,以百分之一英寸为单位。

height
Int32

纸张高度,以百分之一英寸为单位。

示例

下面的代码示例使用 comboPaperSize 打印机支持的纸张大小填充组合框。 此外,还会创建自定义纸张大小并将其添加到组合框。 PaperName标识为 属性,该属性将为通过DisplayMember组合框的 属性添加的项提供显示字符串。 该示例假定存在名为 PrintDocumentprintDoc 变量,并且存在特定的组合框。

// Add list of supported paper sizes found on the printer.
// The DisplayMember property is used to identify the property that will provide the display String*.
comboPaperSize->DisplayMember = "PaperName";
PaperSize^ pkSize;
for ( int i = 0; i < printDoc->PrinterSettings->PaperSizes->Count; i++ )
{
   pkSize = printDoc->PrinterSettings->PaperSizes[ i ];
   comboPaperSize->Items->Add( pkSize );
}

// Create a PaperSize and specify the custom paper size through the constructor and add to combobox.
PaperSize^ pkCustomSize1 = gcnew PaperSize( "First custom size",100,200 );
comboPaperSize->Items->Add( pkCustomSize1 );
// Add list of supported paper sizes found on the printer. 
// The DisplayMember property is used to identify the property that will provide the display string.
comboPaperSize.DisplayMember = "PaperName";

PaperSize pkSize;
for (int i = 0; i < printDoc.PrinterSettings.PaperSizes.Count; i++){
    pkSize = printDoc.PrinterSettings.PaperSizes[i];
    comboPaperSize.Items.Add(pkSize);
}

// Create a PaperSize and specify the custom paper size through the constructor and add to combobox.
PaperSize pkCustomSize1 = new PaperSize("First custom size", 100, 200);

comboPaperSize.Items.Add(pkCustomSize1);
' Add list of supported paper sizes found on the printer. 
' The DisplayMember property is used to identify the property that will provide the display string.
comboPaperSize.DisplayMember = "PaperName"

Dim pkSize As PaperSize
For i = 0 to printDoc.PrinterSettings.PaperSizes.Count - 1
    pkSize = printDoc.PrinterSettings.PaperSizes.Item(i)
    comboPaperSize.Items.Add(pkSize)
Next

' Create a PaperSize and specify the custom paper size through the constructor and add to combobox.
Dim pkCustomSize1 As New PaperSize("Custom Paper Size", 100, 200)

comboPaperSize.Items.Add(pkCustomSize1)

注解

使用此 PaperSize 构造函数创建的 始终将其 Kind 属性设置为 CustomWidthHeight 属性值只能为自定义PaperSize对象设置。

适用于