PrintTicket.PageMediaSize 属性

定义

获取或设置打印机在执行打印作业时所用的纸张(或其他介质)的页面大小。

public:
 property System::Printing::PageMediaSize ^ PageMediaSize { System::Printing::PageMediaSize ^ get(); void set(System::Printing::PageMediaSize ^ value); };
public System.Printing.PageMediaSize PageMediaSize { get; set; }
member this.PageMediaSize : System.Printing.PageMediaSize with get, set
Public Property PageMediaSize As PageMediaSize

属性值

一个 PageMediaSize 对象,使用名称、维度或二者兼之来表示页面大小。

例外

调用代码操作尝试使用至少具有一个 null 属性的 PageMediaSize 对象设置该属性。

- 或 -

调用代码操作尝试使用 PageMediaSize 对象来设置属性,该对象的 PageMediaSizeName 属性被设置为不在 PageMediaSizeName 枚举范围之内的值。

- 或 -

调用代码操作尝试使用 PageMediaSize 对象来设置属性,该对象的 WidthHeight 属性被设置为小于 1 的值。

示例

以下示例演示如何使用此属性缩放视觉元素,使其适合打印纸张的边距。

/// <summary>
///   Returns a scaled copy of a given visual transformed to
///   fit for printing to a specified print queue.</summary>
/// <param name="v">
///   The visual to be printed.</param>
/// <param name="pq">
///   The print queue to be output to.</param>
/// <returns>
///   The root element of the transformed visual.</returns>
private Visual PerformTransform(Visual v, PrintQueue pq)
{
    ContainerVisual root = new ContainerVisual();
    const double inch = 96;

    // Set the margins.
    double xMargin = 1.25 * inch;
    double yMargin = 1 * inch;

    PrintTicket pt = pq.UserPrintTicket;
    Double printableWidth = pt.PageMediaSize.Width.Value;
    Double printableHeight = pt.PageMediaSize.Height.Value;

    Double xScale = (printableWidth - xMargin * 2) / printableWidth;
    Double yScale = (printableHeight - yMargin * 2) / printableHeight;

    root.Children.Add(v);
    root.Transform = new MatrixTransform(xScale, 0, 0, yScale, xMargin, yMargin);

    return root;
}// end:PerformTransform()
''' <summary>
'''   Returns a scaled copy of a given visual transformed to
'''   fit for printing to a specified print queue.</summary>
''' <param name="v">
'''   The visual to be printed.</param>
''' <param name="pq">
'''   The print queue to be output to.</param>
''' <returns>
'''   The root element of the transformed visual.</returns>
Private Function PerformTransform(ByVal v As Visual, ByVal pq As PrintQueue) As Visual
    Dim root As New ContainerVisual()
    Const inch As Double = 96

    ' Set the margins.
    Dim xMargin As Double = 1.25 * inch
    Dim yMargin As Double = 1 * inch

    Dim pt As PrintTicket = pq.UserPrintTicket
    Dim printableWidth As Double = pt.PageMediaSize.Width.Value
    Dim printableHeight As Double = pt.PageMediaSize.Height.Value

    Dim xScale As Double = (printableWidth - xMargin * 2) / printableWidth
    Dim yScale As Double = (printableHeight - yMargin * 2) / printableHeight

    root.Children.Add(v)
    root.Transform = New MatrixTransform(xScale, 0, 0, yScale, xMargin, yMargin)

    Return root
End Function ' end:PerformTransform()

注解

此属性对应于打印架构PageMediaSize关键字 (keyword) 。

可以使用 属性测试打印机支持 PageMediaSizeCapability 的选项。

适用于