Freigeben über


Region.Transform-Methode

Transformiert diese Region mit der angegebenen Matrix.

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

Syntax

'Declaration
Public Sub Transform ( _
    matrix As Matrix _
)
'Usage
Dim instance As Region
Dim matrix As Matrix

instance.Transform(matrix)
public void Transform (
    Matrix matrix
)
public:
void Transform (
    Matrix^ matrix
)
public void Transform (
    Matrix matrix
)
public function Transform (
    matrix : Matrix
)

Parameter

  • matrix
    Die Matrix, mit der diese Region transformiert werden soll.

Ausnahmen

Ausnahmetyp Bedingung

ArgumentNullException

matrix ist NULL (Nothing in Visual Basic).

Beispiel

Das folgende Codebeispiel ist für die Verwendung mit Windows Forms vorgesehen und erfordert PaintEventArgse, wobei es sich um einen Parameter des Paint-Ereignishandlers handelt. Der Code führt die folgenden Aktionen aus:

  • Erstellt ein Rechteck und zeichnet es in Blau auf dem Bildschirm.

  • Erstellt einen Bereich aus dem Rechteck.

  • Erstellt eine Transformationsmatrix und legt diese auf 45 Grad fest.

  • Weist die Transformation dem Bereich zu.

  • Füllt den transformierten Bereich in der Farbe Rot und zeichnet den transformierten Bereich in Rot auf dem Bildschirm.

Beachten Sie, dass das rote Rechteck im Vergleich zum ursprünglichen, blauen Rechteck um 45 Grad gedreht ist.

Public Sub TransformExample(ByVal e As PaintEventArgs)

    ' Create the first rectangle and draw it to the screen in blue.
    Dim regionRect As New Rectangle(100, 50, 100, 100)
    e.Graphics.DrawRectangle(Pens.Blue, regionRect)

    ' Create a region using the first rectangle.
    Dim myRegion As New [Region](regionRect)

    ' Create a transform matrix and set it to have a 45 degree
    ' rotation.
    Dim transformMatrix As New Matrix
    transformMatrix.RotateAt(45, New PointF(100, 50))

    ' Apply the transform to the region.
    myRegion.Transform(transformMatrix)

    ' Fill the transformed region with red and draw it to the
    ' screen in red.
    Dim myBrush As New SolidBrush(Color.Red)
    e.Graphics.FillRegion(myBrush, myRegion)
End Sub
public void TransformExample(PaintEventArgs e)
{
             
    // Create the first rectangle and draw it to the screen in blue.
    Rectangle regionRect = new Rectangle(100, 50, 100, 100);
    e.Graphics.DrawRectangle(Pens.Blue, regionRect);
             
    // Create a region using the first rectangle.
    Region myRegion = new Region(regionRect);
             
    // Create a transform matrix and set it to have a 45 degree
             
    // rotation.
    Matrix transformMatrix = new Matrix();
    transformMatrix.RotateAt(45, new Point(100, 50));
             
    // Apply the transform to the region.
    myRegion.Transform(transformMatrix);
             
    // Fill the transformed region with red and draw it to the screen
             
    // in red.
    SolidBrush myBrush = new SolidBrush(Color.Red);
    e.Graphics.FillRegion(myBrush, myRegion);
}
public:
   void TransformExample( PaintEventArgs^ e )
   {
      
      // Create the first rectangle and draw it to the screen in blue.
      Rectangle regionRect = Rectangle(100,50,100,100);
      e->Graphics->DrawRectangle( Pens::Blue, regionRect );
      
      // Create a region using the first rectangle.
      System::Drawing::Region^ myRegion = gcnew System::Drawing::Region( regionRect );
      
      // Create a transform matrix and set it to have a 45 degree
      // rotation.
      Matrix^ transformMatrix = gcnew Matrix;
      transformMatrix->RotateAt( 45, Point(100,50) );
      
      // Apply the transform to the region.
      myRegion->Transform(transformMatrix);
      
      // Fill the transformed region with red and draw it to the screen
      // in red.
      SolidBrush^ myBrush = gcnew SolidBrush( Color::Red );
      e->Graphics->FillRegion( myBrush, myRegion );
   }
public void TransformExample(PaintEventArgs e)
{
    // Create the first rectangle and draw it to the screen in blue.
    Rectangle regionRect = new Rectangle(100, 50, 100, 100);

    e.get_Graphics().DrawRectangle(Pens.get_Blue(), regionRect);

    // Create a region using the first rectangle.
    Region myRegion = new Region(regionRect);

    // Create a transform matrix and set it to have a 45 degree
    // rotation.
    Matrix transformMatrix = new Matrix();
    
    transformMatrix.RotateAt((float)45, new PointF(100, 50));

    // Apply the transform to the region.
    myRegion.Transform(transformMatrix);

    // Fill the transformed region with red and draw it to the screen
    // in red.
    SolidBrush myBrush = new SolidBrush(Color.get_Red());

    e.get_Graphics().FillRegion(myBrush, myRegion);
} //TransformExample

Plattformen

Windows 98, Windows 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

.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

Siehe auch

Referenz

Region-Klasse
Region-Member
System.Drawing-Namespace