Прочитај на енглеском Уреди

Делите путем


Region.Transform(Matrix) Method

Definition

Transforms this Region by the specified Matrix.

C#
public void Transform(System.Drawing.Drawing2D.Matrix matrix);

Parameters

matrix
Matrix

The Matrix by which to transform this Region.

Exceptions

matrix is null.

Examples

The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e, which is a parameter of the Paint event handler. The code performs the following actions:

  • Creates a rectangle and draws it to the screen in blue.

  • Creates a region from the rectangle.

  • Creates a transformation matrix and sets it to 45 degrees.

  • Applies the transformation to the region.

  • Fills the transformed region with red and draws the transformed region to the screen in red.

Notice that the red rectangle is rotated 45 degrees from the original rectangle, shown in blue.

C#
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);
}

Applies to

Производ Верзије
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 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
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10