LinearGradientBrush.Clone Method
.NET Framework 2.0
Creates an exact copy of this LinearGradientBrush.
Namespace: System.Drawing.Drawing2D
Assembly: System.Drawing (in system.drawing.dll)
Assembly: System.Drawing (in system.drawing.dll)
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.
-
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); }
private void CloneExample(PaintEventArgs e)
{
// Create a LinearGradientBrush.
int x = 20;
int y = 20;
int h = 100;
int w = 200;
Rectangle myRect = new Rectangle(x, y, w, h);
LinearGradientBrush myLGBrush = new LinearGradientBrush(myRect,
Color.get_Blue(), Color.get_Aquamarine(), 45, true);
// Draw an ellipse to the screen using the LinearGradientBrush.
e.get_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, 0);
// Draw a second ellipse to the screen using the cloned HBrush.
y = 150;
e.get_Graphics().FillEllipse(clonedLGBrush, x, y, w, h);
} //CloneExample
Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.