PathGradientBrush::ScaleTransform Method (Single, Single, MatrixOrder)

 

Scales the local geometric transform by the specified amounts in the specified order.

Namespace:   System.Drawing.Drawing2D
Assembly:  System.Drawing (in System.Drawing.dll)

public:
void ScaleTransform(
	float sx,
	float sy,
	MatrixOrder order
)

Parameters

sx
Type: System::Single

The transform scale factor in the x-axis direction.

sy
Type: System::Single

The transform scale factor in the y-axis direction.

order
Type: System.Drawing.Drawing2D::MatrixOrder

A MatrixOrder that specifies whether to append or prepend the scaling matrix.

The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, an OnPaint event object. The code

  • Creates a graphics path and adds a rectangle to it.

  • Creates a PathGradientBrush from the path points (in this example, the points form a rectangle, but it could be most any shape).

  • Sets the center color to red and the surrounding color to blue.

  • Draws the PathGradientBrush to the screen prior to applying the scale transform.

  • Applies the scale transform to the brush by using its ScaleTransform method.

  • Calls the TranslateTransform method to move the brush rectangle such that it does not overlay the one drawn to the screen earlier.

  • Draws the translated brush rectangle to the screen.

Notice that the bottom rectangle is twice as long in the x-axis as is the one drawn prior to the translation.

public:
   void ScaleTransformExample( PaintEventArgs^ e )
   {
      // Create a graphics path and add a rectangle.
      GraphicsPath^ myPath = gcnew GraphicsPath;
      Rectangle rect = Rectangle(100,20,100,50);
      myPath->AddRectangle( rect );

      // Get the path's array of points.
      array<PointF>^myPathPointArray = myPath->PathPoints;

      // Create a path gradient brush.
      PathGradientBrush^ myPGBrush = gcnew PathGradientBrush( myPathPointArray );

      // Set the color span.
      myPGBrush->CenterColor = Color::Red;
      array<Color>^ mySurroundColor = {Color::Blue};
      myPGBrush->SurroundColors = mySurroundColor;

      // Draw the brush to the screen prior to transformation.
      e->Graphics->FillRectangle( myPGBrush, 10, 10, 200, 200 );

      // Scale by a factor of 2 in the x-axis by applying the scale
      // transform to the brush.
      myPGBrush->ScaleTransform( 2, 1, MatrixOrder::Append );

      // Move the brush down by 100 by Applying the translate
      // transform to the brush.
      myPGBrush->TranslateTransform(  -100, 100, MatrixOrder::Append );

      // Draw the brush to the screen again after applying the
      // transforms.
      e->Graphics->FillRectangle( myPGBrush, 10, 10, 300, 300 );
   }

.NET Framework
Available since 1.1
Return to top
Show: