PageMediaSize 類別

定義

描述紙張或其他媒體的頁面大小。

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

範例

下列範例示範如何使用這個類別來調整視覺元素,以符合要列印的紙張邊界。

/// <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 相同的資訊,也包含頁面可影像區域的相關資訊,請參閱 PrintDocumentImageableArea

警告

不支援命名空間內的 System.Printing 類別用於 Windows 服務或 ASP.NET 應用程式或服務。 嘗試從其中一個應用程式類型內使用這些類別可能會產生非預期的問題,例如服務效能降低和執行時間例外狀況。

如果您想要從Windows Forms應用程式列印,請參閱 System.Drawing.Printing 命名空間。

建構函式

PageMediaSize(Double, Double)

使用寬度和高度,初始化 PageMediaSize 類別的新執行個體。

PageMediaSize(PageMediaSizeName)

使用指定的 PageMediaSize 來初始化 PageMediaSizeName 類別的新執行個體。

PageMediaSize(PageMediaSizeName, Double, Double)

使用指定的 PageMediaSize 以及寬度和高度,初始化 PageMediaSizeName 類別的新執行個體。

屬性

Height

取得頁面高度。

PageMediaSizeName

取得紙張或其他媒體的頁面大小名稱。

Width

取得頁面寬度。

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

顯示紙張或其他媒體的頁面大小。

適用於