初始化 PaperSize 类的新实例。
命名空间: System.Drawing.Printing
程序集: System.Drawing(在 System.Drawing.dll 中)
参数
-
name
-
类型:
System.String
纸张名称。
-
width
-
类型:
System.Int32
纸张宽度,以百分之一英寸为单位。
-
height
-
类型:
System.Int32
纸张高度,以百分之一英寸为单位。
下面的代码示例用打印机支持的纸张大小填充 comboPaperSize 组合框。 此外,创建自定义纸张大小并将它添加到组合框中。 PaperName 被标识为一种属性,该属性将向通过组合框的DisplayMember 属性添加的项提供显示字符串。 该示例假定名为 printDoc 的变量 PrintDocument 和特定的组合框都已存在。
// 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);