Export (0) Print
Expand All

LinearGradientBrush.Clone Method

Creates an exact copy of this LinearGradientBrush.

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

public override Object Clone()

Return Value

Type: System.Object
The LinearGradientBrush this method creates, cast as an object.

Implements

ICloneable.Clone()

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.

  • Draws an ellipse to the screen using this brush.

  • Clones the LinearGradientBrush (clonedLGBrush).

  • Draws an ellipse to the screen directly below the first ellipse, using the cloned brush.

private void CloneExample(PaintEventArgs e)
{

    // Create a LinearGradientBrush. 
    int x=20, y=20, h=100, w=200;
    Rectangle myRect = new Rectangle(x, y, w, h);
    LinearGradientBrush myLGBrush = new LinearGradientBrush(
        myRect, Color.Blue, Color.Aquamarine, 45.0f, true);

    // Draw an ellipse to the screen using the LinearGradientBrush.
    e.Graphics.FillEllipse(myLGBrush, x, y, w, h);

    // Clone the LinearGradientBrush.
    LinearGradientBrush clonedLGBrush =
        (LinearGradientBrush)myLGBrush.Clone();

    // Justify the left edge of the gradient with the 
    // left edge of the ellipse.
    clonedLGBrush.TranslateTransform(-100.0f, 0.0f);

    // Draw a second ellipse to the screen using the cloned HBrush.
    y=150;
    e.Graphics.FillEllipse(clonedLGBrush, x, y, w, h);
}

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft