Bewerken

Share via


PathGradientBrush Class

Definition

Encapsulates a Brush object that fills the interior of a GraphicsPath object with a gradient. This class cannot be inherited.

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

Examples

The following code example shows how to create a PathGradientBrush. This example is designed for use with Windows Forms, and it requires the PaintEventArgs e, which is a parameter of PaintEventHandler.

public void FillEllipseWithPathGradient(PaintEventArgs e)
{
    // Create a path that consists of a single ellipse.
    GraphicsPath path = new GraphicsPath();
    path.AddEllipse(0, 0, 140, 70);

    // Use the path to construct a brush.
    PathGradientBrush pthGrBrush = new PathGradientBrush(path);

    // Set the color at the center of the path to blue.
    pthGrBrush.CenterColor = Color.FromArgb(255, 0, 0, 255);

    // Set the color along the entire boundary 
    // of the path to aqua.
    Color[] colors = { Color.FromArgb(255, 0, 255, 255) };
    pthGrBrush.SurroundColors = colors;

    e.Graphics.FillEllipse(pthGrBrush, 0, 0, 140, 70);
}
' Create a path that consists of a single ellipse.
Dim path As New GraphicsPath()
path.AddEllipse(0, 0, 140, 70)

' Use the path to construct a brush.
Dim pthGrBrush As New PathGradientBrush(path)

' Set the color at the center of the path to blue.
pthGrBrush.CenterColor = Color.FromArgb(255, 0, 0, 255)

' Set the color along the entire boundary 
' of the path to aqua.
Dim colors As Color() = {Color.FromArgb(255, 0, 255, 255)}
pthGrBrush.SurroundColors = colors

e.Graphics.FillEllipse(pthGrBrush, 0, 0, 140, 70)

Remarks

The color gradient is a smooth shading of colors from the center point of the path to the outside boundary edge of the path. Blend factors, positions, and style affect where the gradient starts and ends, and how fast it changes shade.

Path gradient brushes do not obey the SmoothingMode property of the Graphics object used to do the drawing. Areas filled using a PathGradientBrush object are rendered the same way (aliased) regardless of the smoothing mode.

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

PathGradientBrush(GraphicsPath)

Initializes a new instance of the PathGradientBrush class with the specified path.

PathGradientBrush(Point[], WrapMode)

Initializes a new instance of the PathGradientBrush class with the specified points and wrap mode.

PathGradientBrush(Point[])

Initializes a new instance of the PathGradientBrush class with the specified points.

PathGradientBrush(PointF[], WrapMode)

Initializes a new instance of the PathGradientBrush class with the specified points and wrap mode.

PathGradientBrush(PointF[])

Initializes a new instance of the PathGradientBrush class with the specified points.

PathGradientBrush(ReadOnlySpan<Point>)

Initializes a new instance of the PathGradientBrush class with the specified points.

PathGradientBrush(ReadOnlySpan<PointF>)

Initializes a new instance of the PathGradientBrush class with the specified points.

PathGradientBrush(WrapMode, ReadOnlySpan<Point>)

Initializes a new instance of the PathGradientBrush class with the specified points and wrap mode.

PathGradientBrush(WrapMode, ReadOnlySpan<PointF>)

Initializes a new instance of the PathGradientBrush class with the specified points and wrap mode.

Properties

Blend

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

CenterColor

Gets or sets the color at the center of the path gradient.

CenterPoint

Gets or sets the center point of the path gradient.

FocusScales

Gets or sets the focus point for the gradient falloff.

InterpolationColors

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

Rectangle

Gets a bounding rectangle for this PathGradientBrush.

SurroundColors

Gets or sets an array of colors that correspond to the points in the path this PathGradientBrush fills.

Transform

Gets or sets a copy of the Matrix that defines a local geometric transform for this PathGradientBrush.

WrapMode

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

Methods

Clone()

Creates an exact copy of this PathGradientBrush.

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, MatrixOrder)

Updates the brush's transformation matrix with the product of the brush's transformation matrix multiplied by another matrix.

MultiplyTransform(Matrix)

Updates the brush's transformation matrix with the product of brush's transformation matrix multiplied by another matrix.

ResetTransform()

Resets the Transform property to identity.

RotateTransform(Single, MatrixOrder)

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

RotateTransform(Single)

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

ScaleTransform(Single, Single, MatrixOrder)

Scales the local geometric transform by the specified amounts 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.

SetBlendTriangularShape(Single, Single)

Creates a gradient with a center color and a linear falloff to each surrounding color.

SetBlendTriangularShape(Single)

Creates a gradient with a center color and a linear falloff to one surrounding color.

SetNativeBrush(IntPtr)

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

(Inherited from Brush)
SetSigmaBellShape(Single, Single)

Creates a gradient brush that changes color starting from the center of the path outward to the path's boundary. The transition from one color to another is based on a bell-shaped curve.

SetSigmaBellShape(Single)

Creates a gradient brush that changes color starting from the center of the path outward to the path's boundary. The transition from one color to another is based on a bell-shaped curve.

ToString()

Returns a string that represents the current object.

(Inherited from Object)
TranslateTransform(Single, Single, MatrixOrder)

Applies the specified translation to the local geometric transform in the specified order.

TranslateTransform(Single, Single)

Applies the specified translation to the local geometric transform. This method prepends the translation to the transform.

Applies to

See also