The following example creates a linear gradient brush and uses it to fill a rectangle. Next, the code changes the linear colors and uses the modified brush to fill another rectangle.
C++
VOID Example_SetLinColors(HDC hdc)
{
Graphics myGraphics(hdc);
LinearGradientBrush linGrBrush(
Rect(0, 0, 100, 50),
Color(255, 255, 0, 0), // red
Color(255, 0, 0, 255), // blue
LinearGradientModeHorizontal);
myGraphics.FillRectangle(&linGrBrush, 0, 0, 100, 50);
linGrBrush.SetLinearColors(
Color(255, 0, 0, 255), // blue
Color(255, 0, 255, 0)); // green
myGraphics.FillRectangle(&linGrBrush, 0, 75, 100, 50);
}
PowerBASIC
SUB GDIP_SetLineColors (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pLinBrush AS DWORD
LOCAL rc AS RECTF
LOCAL colorRed AS DWORD
LOCAL colorBlue AS DWORD
LOCAL colorGreen AS DWORD
hStatus = GdipCreateFromHDC(hdc, pGraphics)
rc.x = 0 : rc.y = 0 : rc.Width = 100 : rc.Height = 50
colorRed = GDIP_ARGB(255, 255, 0, 0)
colorBlue = GDIP_ARGB(255, 0, 0, 255)
colorGreen = GDIP_ARGB(255, 0, 255, 0)
hStatus = GdipCreateLineBrushFromRect(rc, colorRed, colorBlue, %LinearGradientModeHorizontal, %WrapModeTile, pLinBrush)
hStatus = GdipFillRectangle(pGraphics, pLinBrush, 0, 0, 100, 50)
hStatus = GdipSetLineColors(pLinBrush, colorBlue, colorGreen)
hStatus = GdipFillRectangle(pGraphics, pLinBrush, 0, 75, 100, 50)
' // Cleanup
IF pLinBrush THEN GdipDeleteBrush(pLinBrush)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
(http://www.jose.it-berater.org/captures/GdipSetLineColors.png)