PageMediaSize Class (System.Printing)

Switch View :
ScriptFree
.NET Framework Class Library
PageMediaSize Class

Describes the page size for paper or other media.

Inheritance Hierarchy

System.Object
  System.Printing.PageMediaSize

Namespace:  System.Printing
Assembly:  ReachFramework (in ReachFramework.dll)
Syntax

Visual Basic
Public NotInheritable Class PageMediaSize
C#
public sealed class PageMediaSize
Visual C++
public ref class PageMediaSize sealed
F#
[<Sealed>]
type PageMediaSize =  class end

The PageMediaSize type exposes the following members.

Constructors

  Name Description
Public method PageMediaSize(PageMediaSizeName) Initializes a new instance of the PageMediaSize class by using the specified PageMediaSizeName.
Public method PageMediaSize(Double, Double) Initializes a new instance of the PageMediaSize class by using the width and height.
Public method PageMediaSize(PageMediaSizeName, Double, Double) Initializes a new instance of the PageMediaSize class by using the specified PageMediaSizeName and the width and height.
Top
Properties

  Name Description
Public property Height Gets the page height.
Public property PageMediaSizeName Gets the name of the page size for paper or other media.
Public property Width Gets the page width.
Top
Methods

  Name Description
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ToString Displays the page size for paper or other media. (Overrides Object.ToString().)
Top
Remarks

For 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.

Examples

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.

Visual Basic

		''' <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()


C#

/// <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()


Version Information

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also

Reference