LinearGradientBrush::TranslateTransform Method (Single, Single, MatrixOrder)
Translates the local geometric transform by the specified dimensions in the specified order.
Assembly: System.Drawing (in System.Drawing.dll)
Parameters
- dx
-
Type:
System::Single
The value of the translation in x.
- dy
-
Type:
System::Single
The value of the translation in y.
- order
-
Type:
System.Drawing.Drawing2D::MatrixOrder
The order (prepend or append) in which to apply the translation.
The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, 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 = Rectangle(20,20,200,100); LinearGradientBrush^ myLGBrush = gcnew 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 ); }
Available since 1.1