Прочетете на английски Редактиране

Споделяне чрез


PageMediaSize Class

Definition

Describes the page size for paper or other media.

C#
public sealed class PageMediaSize
Inheritance
PageMediaSize

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.

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

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.

Внимание

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.

If you want to print from a Windows Forms application, see the System.Drawing.Printing namespace.

Constructors

PageMediaSize(Double, Double)

Initializes a new instance of the PageMediaSize class by using the width and height.

PageMediaSize(PageMediaSizeName, Double, Double)

Initializes a new instance of the PageMediaSize class by using the specified PageMediaSizeName and the width and height.

PageMediaSize(PageMediaSizeName)

Initializes a new instance of the PageMediaSize class by using the specified PageMediaSizeName.

Properties

Height

Gets the page height.

PageMediaSizeName

Gets the name of the page size for paper or other media.

Width

Gets the page width.

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Displays the page size for paper or other media.

Applies to

Продукт Версии
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10