LinearGradientBrush.TranslateTransform Method

Definition

Translates the local geometric transform by the specified dimensions. This method prepends the translation to the transform.

Overloads

TranslateTransform(Single, Single, MatrixOrder)

Translates the local geometric transform by the specified dimensions in the specified order.

TranslateTransform(Single, Single)

Translates the local geometric transform by the specified dimensions. This method prepends the translation to the transform.

TranslateTransform(Single, Single, MatrixOrder)

Source:
LinearGradientBrush.cs
Source:
LinearGradientBrush.cs
Source:
LinearGradientBrush.cs
Source:
LinearGradientBrush.cs
Source:
LinearGradientBrush.cs

Translates the local geometric transform by the specified dimensions in the specified order.

public void TranslateTransform (float dx, float dy, System.Drawing.Drawing2D.MatrixOrder order);

Parameters

dx
Single

The value of the translation in x.

dy
Single

The value of the translation in y.

order
MatrixOrder

The order (prepend or append) in which to apply the translation.

Examples

The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e, an OnPaint event object. The code performs the following actions:

  • Creates a new LinearGradientBrush.

  • Uses this brush to draw a rectangle to the screen that has a linear, left-to-right transition of colors.

  • Rotates the LinearGradientBrush by 90 degrees and scales the gradient.

  • Draws the rectangle, with the rotated and scaled gradient, to the screen.

  • Translates the rectangle so that it has a linear gradient running from top to bottom.

  • Draws the translated rectangle to the screen.

Notice that there are three rectangles displayed the top one showing the left-to-right gradient, the middle one showing the rotated and scaled gradient, and the bottom one showing the final, translated gradient.

private void TranslateTransformExample(PaintEventArgs e)
{
             
    // Create a LinearGradientBrush.
    Rectangle myRect = new Rectangle(20, 20, 200, 100);
    LinearGradientBrush myLGBrush = new LinearGradientBrush(
        myRect, Color.Blue, Color.Red,  0.0f, true);
             
    // Draw a rectangle to the screen using the LinearGradientBrush.
    e.Graphics.FillRectangle(myLGBrush, myRect);
             
    // Rotate the LinearGradientBrush.
    myLGBrush.RotateTransform(90.0f);
             
    // Scale the gradient for the height of the rectangle.
    myLGBrush.ScaleTransform(0.5f, 1.0f);
             
    // Draw to the screen, the rotated and scaled gradient.
    e.Graphics.FillRectangle(myLGBrush, 20, 150, 200, 100);
             
    // Rejustify the brush to start at the top edge of the
    // rectangle.
    myLGBrush.TranslateTransform(-20.0f, 0.0f);
             
    // Draw a third rectangle to the screen using the translated
    // brush.
    e.Graphics.FillRectangle(myLGBrush, 20, 300, 200, 100);
}

Applies to

.NET 9 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (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 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

TranslateTransform(Single, Single)

Source:
LinearGradientBrush.cs
Source:
LinearGradientBrush.cs
Source:
LinearGradientBrush.cs
Source:
LinearGradientBrush.cs
Source:
LinearGradientBrush.cs

Translates the local geometric transform by the specified dimensions. This method prepends the translation to the transform.

public void TranslateTransform (float dx, float dy);

Parameters

dx
Single

The value of the translation in x.

dy
Single

The value of the translation in y.

Examples

For an example, see TranslateTransform.

Applies to

.NET 9 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (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 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9