VB.NET 1.1 Tutorial - GDI+ - LinearGradientBrush


A LinearGradientBrush encapsulates a Brush object with a linear gradient.

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.

The direction of the gradient is specified by the LinearGradientMode enumeration or the angle in the constructor.

There are several different methods for creating a LinearGradientBrush object.

The version I have used previously takes the following arguments:

Public Sub New( _
  ByVal rect As Rectangle, _
  ByVal color1 As Color, _
  ByVal color2 As Color, _
  ByVal linearGradientMode As LinearGradientMode _
)

Where the Parameters are:

  • rect - A Rectangle structure that specifies the bounds of the linear gradient.
  • color1 - A Color structure that represents the starting color for the gradient.
  • color2 - A Color structure that represents the ending color for the gradient.
  • linearGradientMode - A LinearGradientMode enumeration element that specifies the orientation of the gradient. The orientation determines the starting and ending points of the gradient. For example, LinearGradientMode.ForwardDiagonal specifies that the starting point is the upper-left corner of the rectangle and the ending point is the lower-right corner of the rectangle.

Note that the Rectangle that specifies the bounds of the linear gradient shoud be greater that the size of the object you wish to fill.


References

For more information on the LinearGradientBrush class, visit MSDN at microsoft here.

For more information on the LinearGradientMode constructor, visit MSDN at microsoft here.

What Next?

Return to the Tutorial Contents.