Graphics.PageScale-Eigenschaft
Ruft die Skalierung zwischen globalen Einheiten und Seiteneinheiten für dieses Graphics ab oder legt diese fest.
Namespace: System.Drawing
Assembly: System.Drawing (in system.drawing.dll)
Syntax
'Declaration
Public Property PageScale As Single
'Usage
Dim instance As Graphics
Dim value As Single
value = instance.PageScale
instance.PageScale = value
public float PageScale { get; set; }
public:
property float PageScale {
float get ();
void set (float value);
}
/** @property */
public float get_PageScale ()
/** @property */
public void set_PageScale (float value)
public function get PageScale () : float
public function set PageScale (value : float)
Eigenschaftenwert
Diese Eigenschaft gibt einen Wert für die Skalierung zwischen globalen Einheiten und Seiteneinheiten für dieses Graphics an.
Beispiel
Im folgenden Codebeispiel wird die Verwendung des PageScale-Members und des TranslateTransform-Members veranschaulicht, um die Skalierung und den Ursprung beim Zeichnen eines Rechtecks zu ändern.
Dieses Beispiel ist für die Verwendung mit Windows Forms vorgesehen. Fügen Sie den Code in ein Formular ein, und rufen Sie beim Behandeln des Paint-Ereignisses des Formulars die ChangePageScaleAndTranslateTransform
-Methode auf, wobei Sie e als PaintEventArgs übergeben.
Private Sub ChangePageScaleAndTranslateTransform(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.PageScale = 2.0F
' Call TranslateTransform to change the origin of the
' Graphics object.
e.Graphics.TranslateTransform(10.0F, 10.0F)
' Draw the rectangle again.
e.Graphics.DrawRectangle(Pens.Tomato, rectangle1)
' Set the page scale and origin back to their original values.
e.Graphics.PageScale = 1.0F
e.Graphics.TranslateTransform(0.0F, 0.0F)
Dim transparentBrush As New SolidBrush(Color.FromArgb(50, Color.Yellow))
' Create a new rectangle with the coordinates you expect
' after setting PageScale and calling TranslateTransform:
' x = 10 + (20 * 2)
' y = 10 + (20 * 2)
' Width = 50 * 2
' Length = 100 * 2
Dim newRectangle As Rectangle = New Rectangle(50, 50, 100, 200)
' Fill in the rectangle with a semi-transparent color.
e.Graphics.FillRectangle(transparentBrush, newRectangle)
End Sub
private void ChangePageScaleAndTranslateTransform(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.PageScale = 2.0F;
// Call TranslateTransform to change the origin of the
// Graphics object.
e.Graphics.TranslateTransform(10.0F, 10.0F);
// Draw the rectangle again.
e.Graphics.DrawRectangle(Pens.Tomato, rectangle1);
// Set the page scale and origin back to their original values.
e.Graphics.PageScale = 1.0F;
e.Graphics.TranslateTransform(0.0F, 0.0F);
SolidBrush transparentBrush = new SolidBrush(Color.FromArgb(50,
Color.Yellow));
// Create a new rectangle with the coordinates you expect
// after setting PageScale and calling TranslateTransform:
// x = 10 + (20 * 2)
// y = 10 + (20 * 2)
// Width = 50 * 2
// Length = 100 * 2
Rectangle newRectangle = new Rectangle(50, 50, 100, 200);
// Fill in the rectangle with a semi-transparent color.
e.Graphics.FillRectangle(transparentBrush, newRectangle);
}
private:
void ChangePageScaleAndTranslateTransform( 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->PageScale = 2.0F;
// Call TranslateTransform to change the origin of the
// Graphics object.
e->Graphics->TranslateTransform( 10.0F, 10.0F );
// Draw the rectangle again.
e->Graphics->DrawRectangle( Pens::Tomato, rectangle1 );
// Set the page scale and origin back to their original values.
e->Graphics->PageScale = 1.0F;
e->Graphics->TranslateTransform( 0.0F, 0.0F );
SolidBrush^ transparentBrush = gcnew SolidBrush( Color::FromArgb( 50, Color::Yellow ) );
// Create a new rectangle with the coordinates you expect
// after setting PageScale and calling TranslateTransform:
// x = 10 + (20 * 2)
// y = 10 + (20 * 2)
// Width = 50 * 2
// Length = 100 * 2
Rectangle newRectangle = Rectangle(50,50,100,200);
// Fill in the rectangle with a semi-transparent color.
e->Graphics->FillRectangle( transparentBrush, newRectangle );
}
private void ChangePageScaleAndTranslateTransform(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_PageScale(2);
// Call TranslateTransform to change the origin of the
// Graphics object.
e.get_Graphics().TranslateTransform(10, 10);
// Draw the rectangle again.
e.get_Graphics().DrawRectangle(Pens.get_Tomato(), rectangle1);
// Set the page scale and origin back to their original values.
e.get_Graphics().set_PageScale(1);
e.get_Graphics().TranslateTransform(0, 0);
SolidBrush transparentBrush =
new SolidBrush(Color.FromArgb(50, Color.get_Yellow()));
// Create a new rectangle with the coordinates you expect
// after setting PageScale and calling TranslateTransform:
// x = 10 + (20 * 2)
// y = 10 + (20 * 2)
// Width = 50 * 2
// Length = 100 * 2
Rectangle newRectangle = new Rectangle(50, 50, 100, 200);
// Fill in the rectangle with a semi-transparent color.
e.get_Graphics().FillRectangle(transparentBrush, newRectangle);
} //ChangePageScaleAndTranslateTransform
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0