#215 – Other Choices for Gradient Spreads Outside the Fill Area

If a gradient fill has start/stop points that lie within the control, the fill behavior outside the gradient is dictated by the SpreadMethod property of the gradient brush.

In the example below, the gradient starts at X=0.33 and stops at X=0.67.  There are three different values that you can set SpreadMethod to, dictating how the control is filled at X < 0.33 and X > 0.67.

SpreadMethod = GradientSpreadMethod.Pad (the default).  The colors at each end of the gradient are used to fill the rest of the control.

SpreadMethod = GradientSpreadMethod.Reflect. The gradient repeats, reversing its direction, to fill the rest of the control.

SpreadMethod = GradientSpreadMethod.Repeat.  The gradient repeats, but in the original direction.  As much of the gradient as will fit is used.




#214 – Starting/Ending a Gradient Fill Inside a Control

You typically set the StartPoint and EndPoint of a gradient fill at the control’s boundary.  For example, a red-blue gradient might start at the left edge of the control and end at the right edge.  This is done with a StartPoint of (0,0.5) and an EndPoint of (1,0.5).

You can also specify start and end points that are in the interior of the control.  If we specify (0.33,0.5) as the StartPoint and (0.67,0.5) as the EndPoint, we get the following.  (Gradient line drawn, for reference).

We still have a red-to-blue gradient, but the gradient starts 1/3 of the way into the rectangle and finishes 2/3 of the way into the rectangle.

The fill behavior outside the specified gradient line depends on the value of the GradientBrush.SpreadMethod.  The default for this property, GradientSpreadMethod.Pad, specifies that the color at the edge of the gradient should just be extended to the edge of the control.