Graphics.PageUnit Property
Gets or sets the unit of measure used for page coordinates in this Graphics.

Namespace: System.Drawing
Assembly: System.Drawing (in system.drawing.dll)

Syntax

Visual Basic (Declaration)
Public Property PageUnit As GraphicsUnit
Visual Basic (Usage)
Dim instance As Graphics
Dim value As GraphicsUnit

value = instance.PageUnit

instance.PageUnit = value
C#
public GraphicsUnit PageUnit { get; set; }
C++
public:
property GraphicsUnit PageUnit {
    GraphicsUnit get ();
    void set (GraphicsUnit value);
}
J#
/** @property */
public GraphicsUnit get_PageUnit ()

/** @property */
public void set_PageUnit (GraphicsUnit value)
JScript
public function get PageUnit () : GraphicsUnit

public function set PageUnit (value : GraphicsUnit)
XAML
Not applicable.

Property Value

One of the GraphicsUnit values other than World.
Exceptions

Exception typeCondition

InvalidEnumArgumentException

PageUnit is set to World, which is not a physical unit.

Remarks

The graphics unit is the unit of measure used for page coordinates in this Graphics.

Example

The following code example demonstrates the effect of changing the PageUnit property.

This example is designed to be used with Windows Forms. Paste the code into a form and call the ChangePageUnit method when handling the form's Paint event, passing e as PaintEventArgs.

Visual Basic
Private Sub ChangePageUnit(ByVal e As PaintEventArgs)

    ' Create a rectangle.
    Dim rectangle1 As New Rectangle(20, 20, 50, 100)

    ' Draw its outline.
    e.Graphics.DrawRectangle(Pens.SlateBlue, rectangle1)

    ' Change the page scale.  
    e.Graphics.PageUnit = GraphicsUnit.Point

    ' Draw the rectangle again.
    e.Graphics.DrawRectangle(Pens.Tomato, rectangle1)

End Sub
C#
private void ChangePageUnit(PaintEventArgs e)
{

    // Create a rectangle.
    Rectangle rectangle1 = new Rectangle(20, 20, 50, 100);

    // Draw its outline.
    e.Graphics.DrawRectangle(Pens.SlateBlue, rectangle1);

    // Change the page scale.  
    e.Graphics.PageUnit = GraphicsUnit.Point;

    // Draw the rectangle again.
    e.Graphics.DrawRectangle(Pens.Tomato, rectangle1);

}
C++
private:
   void ChangePageUnit( PaintEventArgs^ e )
   {
      // Create a rectangle.
      Rectangle rectangle1 = Rectangle(20,20,50,100);

      // Draw its outline.
      e->Graphics->DrawRectangle( Pens::SlateBlue, rectangle1 );

      // Change the page scale.  
      e->Graphics->PageUnit = GraphicsUnit::Point;

      // Draw the rectangle again.
      e->Graphics->DrawRectangle( Pens::Tomato, rectangle1 );
   }
J#
private void ChangePageUnit(PaintEventArgs e)
{
    // Create a rectangle.
    Rectangle rectangle1 = new Rectangle(20, 20, 50, 100);

    // Draw its outline.
    e.get_Graphics().DrawRectangle(Pens.get_SlateBlue(), rectangle1);

    // Change the page scale.  
    e.get_Graphics().set_PageUnit(GraphicsUnit.Point);

    // Draw the rectangle again.
    e.get_Graphics().DrawRectangle(Pens.get_Tomato(), rectangle1);
} //ChangePageUnit
Platforms

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

Version Information

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
See Also

Tags :


Page view tracker