ערוך

שתף באמצעות


LinearGradientBrush Class

Definition

Encapsulates a Brush with a linear gradient. This class cannot be inherited.

public ref class LinearGradientBrush sealed : System::Drawing::Brush
public sealed class LinearGradientBrush : System.Drawing.Brush
type LinearGradientBrush = class
    inherit Brush
Public NotInheritable Class LinearGradientBrush
Inherits Brush
Inheritance
LinearGradientBrush

Examples

The following example creates a horizontal LinearGradientBrush; the color components change linearly as you move from a horizontal coordinate of 0 to a horizontal coordinate of 200. For example, a point whose first coordinate is halfway between 0 and 200 will have a blue component that is halfway between 0 and 255. This example is designed for use with Windows Forms. The following code example is designed for use with Windows Forms, and it requires the PaintEventArgs e, which is a parameter of PaintEventHandler.

public void UseHorizontalLinearGradients(PaintEventArgs e)
{
    LinearGradientBrush linGrBrush = new LinearGradientBrush(
       new Point(0, 10),
       new Point(200, 10),
       Color.FromArgb(255, 255, 0, 0),   // Opaque red
       Color.FromArgb(255, 0, 0, 255));  // Opaque blue

    Pen pen = new Pen(linGrBrush);

    e.Graphics.DrawLine(pen, 0, 10, 200, 10);
    e.Graphics.FillEllipse(linGrBrush, 0, 30, 200, 100);
    e.Graphics.FillRectangle(linGrBrush, 0, 155, 500, 30);
}
Dim linGrBrush As New LinearGradientBrush( _
   New Point(0, 10), _
   New Point(200, 10), _
   Color.FromArgb(255, 255, 0, 0), _
   Color.FromArgb(255, 0, 0, 255))
Dim pen As New Pen(linGrBrush)

e.Graphics.DrawLine(pen, 0, 10, 200, 10)
e.Graphics.FillEllipse(linGrBrush, 0, 30, 200, 100)
e.Graphics.FillRectangle(linGrBrush, 0, 155, 500, 30)

Remarks

This class encapsulates both two-color gradients and custom multicolor gradients.

All linear gradients are defined along a line specified either by the width of a rectangle or by two points.

By default, a two-color linear gradient is an even horizontal linear blend from the starting color to the ending color along the specified line. Customize the blend pattern using the Blend class, the SetSigmaBellShape methods, or the SetBlendTriangularShape methods. Customize the direction of the gradient by specifying the LinearGradientMode enumeration or the angle in the constructor.

Use the InterpolationColors property to create a multicolor gradient.

The Transform property specifies a local geometric transform applied to the gradient.

Note

In .NET 6 and later versions, the System.Drawing.Common package, which includes this type, is only supported on Windows operating systems. Use of this type in cross-platform apps causes compile-time warnings and run-time exceptions. For more information, see System.Drawing.Common only supported on Windows.

Constructors

LinearGradientBrush(Point, Point, Color, Color)

Initializes a new instance of the LinearGradientBrush class with the specified points and colors.

LinearGradientBrush(PointF, PointF, Color, Color)

Initializes a new instance of the LinearGradientBrush class with the specified points and colors.

LinearGradientBrush(Rectangle, Color, Color, LinearGradientMode)

Creates a new instance of the LinearGradientBrush class based on a rectangle, starting and ending colors, and orientation.

LinearGradientBrush(Rectangle, Color, Color, Single)

Creates a new instance of the LinearGradientBrush class based on a rectangle, starting and ending colors, and an orientation angle.

LinearGradientBrush(Rectangle, Color, Color, Single, Boolean)

Creates a new instance of the LinearGradientBrush class based on a rectangle, starting and ending colors, and an orientation angle.

LinearGradientBrush(RectangleF, Color, Color, LinearGradientMode)

Creates a new instance of the LinearGradientBrush based on a rectangle, starting and ending colors, and an orientation mode.

LinearGradientBrush(RectangleF, Color, Color, Single)

Creates a new instance of the LinearGradientBrush class based on a rectangle, starting and ending colors, and an orientation angle.

LinearGradientBrush(RectangleF, Color, Color, Single, Boolean)

Creates a new instance of the LinearGradientBrush class based on a rectangle, starting and ending colors, and an orientation angle.

Properties

Blend

Gets or sets a Blend that specifies positions and factors that define a custom falloff for the gradient.

GammaCorrection

Gets or sets a value indicating whether gamma correction is enabled for this LinearGradientBrush.

InterpolationColors

Gets or sets a ColorBlend that defines a multicolor linear gradient.

LinearColors

Gets or sets the starting and ending colors of the gradient.

Rectangle

Gets a rectangular region that defines the starting and ending points of the gradient.

Transform

Gets or sets a copy Matrix that defines a local geometric transform for this LinearGradientBrush.

WrapMode

Gets or sets a WrapMode enumeration that indicates the wrap mode for this LinearGradientBrush.

Methods

Clone()

Creates an exact copy of this LinearGradientBrush.

CreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Dispose()

Releases all resources used by this Brush object.

(Inherited from Brush)
Dispose(Boolean)

Releases the unmanaged resources used by the Brush and optionally releases the managed resources.

(Inherited from Brush)
Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetLifetimeService()
Obsolete.

Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService()
Obsolete.

Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
MultiplyTransform(Matrix)

Multiplies the Matrix that represents the local geometric transform of this LinearGradientBrush by the specified Matrix by prepending the specified Matrix.

MultiplyTransform(Matrix, MatrixOrder)

Multiplies the Matrix that represents the local geometric transform of this LinearGradientBrush by the specified Matrix in the specified order.

ResetTransform()

Resets the Transform property to identity.

RotateTransform(Single)

Rotates the local geometric transform by the specified amount. This method prepends the rotation to the transform.

RotateTransform(Single, MatrixOrder)

Rotates the local geometric transform by the specified amount in the specified order.

ScaleTransform(Single, Single)

Scales the local geometric transform by the specified amounts. This method prepends the scaling matrix to the transform.

ScaleTransform(Single, Single, MatrixOrder)

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

SetBlendTriangularShape(Single)

Creates a linear gradient with a center color and a linear falloff to a single color on both ends.

SetBlendTriangularShape(Single, Single)

Creates a linear gradient with a center color and a linear falloff to a single color on both ends.

SetNativeBrush(IntPtr)

In a derived class, sets a reference to a GDI+ brush object.

(Inherited from Brush)
SetSigmaBellShape(Single)

Creates a gradient falloff based on a bell-shaped curve.

SetSigmaBellShape(Single, Single)

Creates a gradient falloff based on a bell-shaped curve.

ToString()

Returns a string that represents the current object.

(Inherited from Object)
TranslateTransform(Single, Single)

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

TranslateTransform(Single, Single, MatrixOrder)

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

Applies to

See also