LinearGradientBrush::LinearGradientBrush(constRect&,constColor&,constColor&,LinearGradientMode) method (gdiplusbrush.h)
Creates a LinearGradientBrush::LinearGradientBrush object based on a rectangle and mode of direction.
Syntax
void LinearGradientBrush(
[in, ref] const Rect & rect,
[in, ref] const Color & color1,
[in, ref] const Color & color2,
[in] LinearGradientMode mode
);
Parameters
[in, ref] rect
Type: const Rect
Reference to a rectangle that specifies the starting and ending points of the gradient. The direction of the gradient, specified by mode, affects how these points are defined. The dimensions of the rectangle affect the direction of the gradient for forward diagonal mode and backward diagonal mode.
[in, ref] color1
Type: const Color
Reference to a Color object that specifies the color at the starting boundary line of this linear gradient brush.
[in, ref] color2
Type: const Color
Reference to a Color object that specifies the color at the ending boundary line of this linear gradient brush.
[in] mode
Type: LinearGradientMode
Element of the LinearGradientMode enumeration that specifies the direction of the gradient.
Return value
None
Remarks
The starting boundary of the gradient is a straight line that either passes through the starting point or borders the rectangle rect. The ending boundary of the gradient is a straight line that is parallel to the starting boundary line and that either passes through the ending point or borders the rectangle. The "directional line," an imaginary straight line, is perpendicular to the boundary lines. The gradient color is constant along lines that are parallel to the boundary lines. The gradient gradually changes from the starting color to the ending color along the directional line.
The mode affects the boundaries of the gradient:
- Vertical mode The boundary lines are parallel to the top (and bottom) of the rectangle rect. The starting and ending boundary lines are the top and bottom, respectively, of the rectangle rect.
- Horizontal mode The boundary lines are parallel to the left (and right) of the rectangle rect. The starting and ending boundary lines are the left and right, respectively, of the rectangle rect.
- Forward diagonal mode The boundary lines are parallel to the diagonal line that is defined by the upper-right corner and lower-left corner of the rectangle rect. The starting boundary line passes through the starting point (upper-left corner of the rectangle rect). The ending boundary line passes through the ending point (lower-right corner of the rectangle rect). Note that starting and ending points are opposites of the starting and ending points for backward diagonal mode.
- Backward diagonal mode The boundary lines are parallel to the diagonal line that is defined by the upper-left corner and lower-right corner of the rectangle rect. The starting boundary line passes through the starting point (upper-right corner of the rectangle rect). The ending boundary line passes through the ending point (lower-left corner of the rectangle rect). Note that starting and ending points are opposites of the starting and ending points for forward diagonal mode.
Examples
The following example creates a linear gradient brush using LinearGradientModeVertical for the mode setting.
VOID Example_Construct04(HDC hdc)
{
Graphics myGraphics(hdc);
LinearGradientBrush linGrBrush(
Rect(20, 10, 200, 100),
Color(255, 255, 0, 0), // red
Color(255, 0, 0, 255), // blue
LinearGradientModeVertical);
myGraphics.FillRectangle(&linGrBrush, 0, 0, 300, 300);
}
Requirements
Requirement | Value |
---|---|
Minimum supported client | Windows XP, Windows 2000 Professional [desktop apps only] |
Minimum supported server | Windows 2000 Server [desktop apps only] |
Target Platform | Windows |
Header | gdiplusbrush.h (include Gdiplus.h) |
Library | Gdiplus.lib |
DLL | Gdiplus.dll |