To produce a similar advanced gradient style in your program you'll have to write the following code:
C# |
Copy Code
|
---|---|
NAdvancedGradientFillStyle gradient = new NAdvancedGradientFillStyle(); gradient.BackgroundColor = Color.White; gradient.Points.Add(new NAdvancedGradientPoint(Color.Red, 14, 16, 0, 70, AGPointShape.Circle)); gradient.Points.Add(new NAdvancedGradientPoint(Color.Yellow, 84, 36, 25, 70, AGPointShape.Rectangle)); gradient.Points.Add(new NAdvancedGradientPoint(Color.Magenta, 60, 89, 0, 50, AGPointShape.Line)); someObject.FillStyle = gradient; |
Visual Basic |
Copy Code
|
---|---|
Dim gradient As New NAdvancedGradientFillStyle gradient.BackgroundColor = Color.White gradient.Points.Add(New NAdvancedGradientPoint(Color.Red, 14, 16, 0, 70, AGPointShape.Circle)) gradient.Points.Add(New NAdvancedGradientPoint(Color.Yellow, 84, 36, 25, 70, AGPointShape.Rectangle)) gradient.Points.Add(New NAdvancedGradientPoint(Color.Magenta, 60, 89, 0, 50, AGPointShape.Line)) someObject.FillStyle = gradient |
Now let's investigate each line in detail in order to see the purpose behind it. The first line of code:
C# |
Copy Code
|
---|---|
NAdvancedGradientFillStyle gradient = new NAdvancedGradientFillStyle();
|
Visual Basic |
Copy Code
|
---|---|
Dim gradient As New NAdvancedGradientFillStyle |
creates a new NAdvancedGradientFillStyle 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:
C# |
Copy Code
|
---|---|
gradient.BackgroundColor = Color.White; |
Visual Basic |
Copy Code
|
---|---|
gradient.BackgroundColor = Color.White |
and add some gradient points with different position, shape and intensity:
C# |
Copy Code
|
---|---|
gradient.Points.Add(new NAdvancedGradientPoint(Color.Red, 14, 16, 0, 70, AGPointShape.Circle)); gradient.Points.Add(new NAdvancedGradientPoint(Color.Yellow, 84, 36, 25, 70, AGPointShape.Rectangle)); gradient.Points.Add(new NAdvancedGradientPoint(Color.Magenta, 60, 89, 0, 50, AGPointShape.Line)); |
Visual Basic |
Copy Code
|
---|---|
gradient.Points.Add(New NAdvancedGradientPoint(Color.Red, 14, 16, 0, 70, AGPointShape.Circle)) gradient.Points.Add(New NAdvancedGradientPoint(Color.Yellow, 84, 36, 25, 70, AGPointShape.Rectangle)) gradient.Points.Add(New NAdvancedGradientPoint(Color.Magenta, 60, 89, 0, 50, AGPointShape.Line)) |
The NAdvancedGradientPoint 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, whereas (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 NAdvancedGradientPoint object also exposes the above parameters as properties so you can create an advanced gradient point with the default constructor and afterwards modify its properties.
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.
C# |
Copy Code
|
---|---|
someObject.FillStyle = gradient; |
Visual Basic |
Copy Code
|
---|---|
someObject.FillStyle = gradient |