Xceed Chart for WinForms v4.4 Documentation
Advanced Gradient

Welcome to Xceed Chart for WinForms v4.4 > User Guide > Fill Effects > Advanced Gradient

Advanced gradients take the idea of simple gradients further by allowing you to create gradients based on circles, lines, and rectangles. An advanced gradient consists of a background color that defines the default color of the gradient and an arbitrary number of points. Each point has properties for shape, color, position, intensity, and angle. The following picture shows an advanced gradient based on three points with a white background color. The points have line, circle, and rectangle shapes: 

To produce a similar advanced gradient in your program, you'll have to write the following code:

VB.NET  

Dim gradient As AdvancedGradientPoint =  New AdvancedGradientPoint()

 

gradient.BackgroundColor = Color.White

 

gradient.Points.Add(New AdvancedGradientPoint(Color.Red,14,16,0,70,AGPointShape.Circle))

gradient.Points.Add(New AdvancedGradientPoint(Color.Yellow,84,36,25,70,AGPointShape.Rectangle))

gradient.Points.Add(New AdvancedGradientPoint(Color.Magenta,60,89,0,50,AGPointShape.Line))

 

fillEffect.SetAdvancedGradient(gradient)

C#  
FillEffect.Type = FillEffectType.AdvancedGradient;
AdvancedGradientPointDescription advancedGradient = FillEffect.AdvancedGradientDescription;
advancedGradient.BackgroundColor = Color.White;

AdvancedGradientPoint point1 = new AdvancedGradientPoint(Color.Red, 14, 16, 0, 70, AGPointShape.Circle);
advancedGradient.Points.Add(point1);

AdvancedGradientPoint point2 = new AdvancedGradientPoint(Color.Yellow, 84, 36, 25, 70, AGPointShape.Rectangle);
advancedGradient.Points.Add(point2);

AdvancedGradientPoint point3 = new AdvancedGradientPoint(Color.Magenta, 60, 89, 0, 50, AGPointShape.Line);
advancedGradient.Points.Add(point3);

Now let's investigate each line in detail to see the purpose behind it. The first line of code:

VB.NET  
Dim gradient As AdvancedGradientFill =  New AdvancedGradientFill()
C#  
AdvancedGradientFill gradient = new AdvancedGradientFill();

creates a new AdvancedGradientFill object, which is used as a description of the advanced gradient. This object contains a collection of advanced gradient points as well as a color for the gradient background. After we create the gradient fill object we modify the background color:

VB.NET  
gradient.BackgroundColor = Color.White
C#  
gradient.BackgroundColor = Color.White;

and add some gradient points with different positions, shapes, and intensities:

VB.NET  

gradient.Points.Add(New AdvancedGradientPoint(Color.Red, 14, 16, 0, 70, AGPointShape.Circle))

gradient.Points.Add(New AdvancedGradientPoint(Color.Yellow, 84, 36, 25, 70, AGPointShape.Rectangle))

gradient.Points.Add(New AdvancedGradientPoint(Color.Magenta, 60, 89, 0, 50, AGPointShape.Line))

C#  

gradient.Points.Add(new AdvancedGradientPoint(Color.Red, 14, 16, 0, 70, AGPointShape.Circle));

gradient.Points.Add(new AdvancedGradientPoint(Color.Yellow, 84, 36, 25, 70, AGPointShape.Rectangle));

gradient.Points.Add(new AdvancedGradientPoint(Color.Magenta, 60, 89, 0, 50, AGPointShape.Line));

The AdvancedGradientPoint constructor accepts 6 parameters. The first one is the color of the point. The gradient is merging this color with the other point's colors for each pixel of the gradient by calculating the distance from the pixel to the point and diminishing the point color influence in the resulting image as this distance grows. 

The color is followed by the position of the point in the range [0, 100], where a position of (0, 0) means the upper left corner and (100, 100) means the lower right corner. The point angle determines the tilting of the point shape and is used only if the point shape is line or rectangle. The point intensity controls the influence of the point in the resulting gradient and ranges in the interval [0, 100]. The last parameter is the shape of the point and it can accept a value from the AGPointShape enumeration, e.g., Circle, Line or Rectangle

The AdvancedGradientPoint object also exposes the above parameters as properties so you can create the object with a parameterless constructor and modify the properties one by one. 

The last row of the example applies the advanced gradient to a fill effect object. The visual element that is associated with that fill effect will be filled with the advanced gradient after the control is refreshed.

VB.NET  
fillEffect.SetAdvancedGradient(gradient)
C#  
fillEffect.SetAdvancedGradient(gradient);

Note that after calling this method any modifications to the gradient object will have no effect. You have to call SetAdvancedGradient every time you want to change the advanced gradient. 

Now that we have covered these steps, you'll be able to create your own advanced gradients. Let's take a look now at the control's built-in advanced gradients. The control supports 24 types of predefined advanced gradient schemes, each of which has 15 variants. This means you have 360 predefined advanced gradients at your disposal! You can load one of these gradients by using the SetPredefinedAdvancedGradient function of the FillEffect object. For example, the following code will load the "Calm Water" gradient scheme with variant 11:

VB.NET  
fillEffect.SetPredefinedAdvancedGradient(AdvancedGradientScheme.CalmWater1, 11)
C#  
fillEffect.SetPredefinedAdvancedGradient(AdvancedGradientScheme.CalmWater1, 11);

When you load a predefined advanced gradient scheme, you can modify it manually afterward by touching the properties of the points or the background color of the gradient. 

The following table lists the 24 types of predefined advanced gradients with only one variant for each scheme. 

White On Black Ocean 3
White On Red Ocean 4
White On Green Calm Water 1
White On Blue Calm Water 2
Red Desert 1
Green Desert 2
Blue Fire 1
Sunset Fire 2
Night Fall Fog 1
Night Fall 2 Fog 2
Ocean 1 Mahagony 1
Ocean 2 Mahagony 2

Advanced gradients are treated internally as normal textures. This is why you can apply some texture transformations to them, such as scaling and rotation. For more information on these features, please read the Texture Mapping topic.

Related Examples

Windows Forms: Fill Effects\General

See Also

FillEffect | Xceed 3D Lighting Model | Working with Lights | Texture Mapping