PageMediaSize 类

定义

描述纸张或其他介质的页大小。Describes the page size for paper or other media.

public ref class PageMediaSize sealed
public sealed class PageMediaSize
type PageMediaSize = class
Public NotInheritable Class PageMediaSize
继承
PageMediaSize

示例

下面的示例演示如何使用此类来缩放可视元素, 使其适合要打印的纸张的边距。The following example shows how to use this class to scale a visual element to fit within the margins of the paper on which it is to print.

/// <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相同的信息的类, 并且还包括有关页面的可成像区域的信息, 请参阅。 PrintDocumentImageableAreaFor a class that includes the same information about the media size as PageMediaSize and also includes information about the imageable area of the page, see PrintDocumentImageableArea.

注意

System.Printing命名空间中的类不支持在 Windows 服务或 ASP.NET 应用程序或服务中使用。Classes within the System.Printing namespace are not supported for use within a Windows service or ASP.NET application or service. 尝试从这些应用程序类型之一中使用这些类可能会产生意外的问题, 例如降低服务性能和运行时异常。Attempting to use these classes from within one of these application types may produce unexpected problems, such as diminished service performance and run-time exceptions.

如果要从 Windows 窗体应用程序进行打印, 请参阅System.Drawing.Printing命名空间。If you want to print from a Windows Forms application, see the System.Drawing.Printing namespace.

构造函数

PageMediaSize(Double, Double)

使用宽度和高度初始化 PageMediaSize 类的一个新实例。Initializes a new instance of the PageMediaSize class by using the width and height.

PageMediaSize(PageMediaSizeName)

使用指定的 PageMediaSize 初始化 PageMediaSizeName 类的新实例。Initializes a new instance of the PageMediaSize class by using the specified PageMediaSizeName.

PageMediaSize(PageMediaSizeName, Double, Double)

使用指定的 PageMediaSize 和宽度及高度初始化 PageMediaSizeName 类的一个新实例。Initializes a new instance of the PageMediaSize class by using the specified PageMediaSizeName and the width and height.

属性

Height

获取页面高度。Gets the page height.

PageMediaSizeName

获取纸张或其他介质页大小的名称。Gets the name of the page size for paper or other media.

Width

获取页面的宽度。Gets the page width.

方法

Equals(Object)

确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

显示纸张或其他介质的页大小。Displays the page size for paper or other media.

适用于