Example 1:
void Ctextdlg::onpaint ()
{
Graphics graphics (This->m_hwnd);
LinearGradientBrush Lingrbrush (
Point (0,0),
Point (200,0),
Color (255,255,0,0),
Color (255,0,0,255));
Graphics. FillRectangle (&lingrbrush, 0, 0, 200, 200);
}
Example 2:
Graphics Graphics (DC. GETSAFEHDC ());
Graphics. Clear (color::white);
//define three different colors to participate in the gradient
Color colors[] =
{
color::red,//Red
color::green,//transition color to green
color::blue//Blue
};
float positions[] =
{
0.0f,//from Red
0.3f,//green starts at One-third of brush length
1.0f//To Blue stop
};
//Construct a gradient brush from black to white
LinearGradientBrush Lingrbrush (
Point (0, 0),
Point (0),
color::black,color::white);
//Set multicolor gradient information for a gradient brush
//lingrbrush.interpolationcolors=clrblend;
lingrbrush.setinterpolationcolors (colors, positions, 3);
//Fill the target area with a multi-color gradient brush
Graphics. FillRectangle (&lingrbrush, 0, 0, N.);
//Using a common method for multicolor gradients
//From red to green, length
LinearGradientBrush LinGrBrush1 (
Point (0, 0),
Point (0),
color::red,
color::green);
From green to blue, length 120
LinearGradientBrush LinGrBrush2 (
Point (60, 0),
Point (181, 0),
Color::green,
Color::blue);
Fill two adjacent areas with two brushes to form a multi-color gradient
Graphics. FillRectangle (&LINGRBRUSH1, 0, 120, 60, 100);
Graphics. FillRectangle (&LINGRBRUSH2, 60, 120, 120, 100);
GDI + Draw Gradient colors