Class

LinearGradientBrush


Description

Creates an image consisting of a progressive transition between two or more colors along a straight line.

Properties

Name

Type

Read-Only

Shared

EndPoint

Point

GradientStops()

Pair

StartPoint

Point

Methods

Name

Parameters

Returns

Shared

Constructor

startPoint As Point, endPoint As Point, stops() As Pair

startPoint As Point, endPoint As Point, ParamArray stops As Pair

Property descriptions


LinearGradientBrush.EndPoint

EndPoint As Point

The location within the Graphics object where the gradient will end.


LinearGradientBrush.GradientStops

GradientStops() As Pair

An array of values indicating the locations where the gradient changes color.

Each element of the array is a Pair where the left value is a position and the right, a Color. The position is the percentage of the area to be drawn with the Color passed.

This example (in the Paint event of a Canvas control) draws an oval with a gradient. The GradientStops property is used to add gradients at 0%, 40%, 70% and 100%. In this example, red will be used from 0% to 40% of the drawing area:

Var linearBrush As New LinearGradientBrush
linearBrush.StartPoint = New Point(0, 0)
linearBrush.EndPoint = New Point(g.Width, g.Height)
linearBrush.GradientStops.Add(New Pair(0.0, Color.Red))
linearBrush.GradientStops.Add(New Pair(0.4, Color.Yellow))
linearBrush.GradientStops.Add(New Pair(0.7, Color.Magenta))
linearBrush.GradientStops.Add(New Pair(1.0, Color.Blue))

g.Brush = linearBrush
g.FillOval(0, 0, g.Width, g.Height)

LinearGradientBrush.StartPoint

StartPoint As Point

The location within the Graphics object where the gradient will start.

Method descriptions


LinearGradientBrush.Constructor

Constructor(startPoint As Point, endPoint As Point, stops() As Pair)

Constructor(startPoint As Point, endPoint As Point, ParamArray stops As Pair)

Creates the LinearGradientBrush from the parameters passed.

Note

The new LinearGradientBrush created will be passed copies of the Points and Pairs parameters.

Notes

Sample code

This code in the Paint event of a Canvas draws an oval filled with a linear gradient:

Var linearBrush As New LinearGradientBrush
linearBrush.StartPoint = New Point(0, 0)
linearBrush.EndPoint = New Point(g.Width, g.Height)
linearBrush.GradientStops.Add(New Pair(0, Color.Red))
linearBrush.GradientStops.Add(New Pair(0.4, Color.Yellow))
linearBrush.GradientStops.Add(New Pair(0.7, Color.Magenta))
linearBrush.GradientStops.Add(New Pair(1.0, Color.Blue))

g.Brush = linearBrush
g.FillOval(0, 0, g.Width, g.Height)

Compatibility

All project types on all supported operating systems.

See also

GraphicsBrush parent class; Graphics.Brush property, PictureBrush, ShadowBrush, and RadialGradientBrush classes.