Region.Transform(Matrix) Méthode

Définition

Transforme cet objet Region en Matrix spécifié.Transforms this Region by the specified Matrix.

public:
 void Transform(System::Drawing::Drawing2D::Matrix ^ matrix);
public void Transform (System.Drawing.Drawing2D.Matrix matrix);
member this.Transform : System.Drawing.Drawing2D.Matrix -> unit
Public Sub Transform (matrix As Matrix)

Paramètres

matrix
Matrix

Matrix par lequel transformer cet objet Region.The Matrix by which to transform this Region.

Exceptions

matrix a la valeur null.matrix is null.

Exemples

L’exemple de code suivant est conçu pour être utilisé avec Windows Forms, et il requiert PaintEventArgs e , qui est un paramètre du Paint Gestionnaire d’événements.The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. Le code effectue les actions suivantes :The code performs the following actions:

  • Crée un rectangle et le dessine à l’écran en bleu.Creates a rectangle and draws it to the screen in blue.

  • Crée une région à partir du rectangle.Creates a region from the rectangle.

  • Crée une matrice de transformation et lui affecte la valeur 45 degrés.Creates a transformation matrix and sets it to 45 degrees.

  • Applique la transformation à la région.Applies the transformation to the region.

  • Remplit la zone transformée en rouge et dessine la zone transformée à l’écran en rouge.Fills the transformed region with red and draws the transformed region to the screen in red.

Notez que le rectangle rouge est pivoté de 45 degrés à partir du rectangle d’origine, indiqué en bleu.Notice that the red rectangle is rotated 45 degrees from the original rectangle, shown in blue.

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

S’applique à