PrintTicket.PageMediaSize 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定印表機用於列印工作的紙張 (或其他媒體) 列印大小。
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 物件,使用名稱、維度或兩者來代表頁面大小。
例外狀況
呼叫程式碼嘗試以 PageMediaSize 物件來設定屬性,而此物件至少有一個 null
屬性。
-或-
呼叫程式碼嘗試以 PageMediaSize 物件來設定屬性,而此物件的 PageMediaSizeName 屬性設定為不屬於 PageMediaSizeName 列舉型別 (Enumeration) 的值。
-或-
呼叫程式碼嘗試以 PageMediaSize 物件來設定屬性,而此物件的 Width 或 Height 屬性設定為小於 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
關鍵詞。
您可以使用 屬性來測試印表機支援 PageMediaSizeCapability 的選項。