After reading this post, read also: Gradient backgrounds in your forms with gdi+ part 2
Gdi+ brings us the possibility to create many cool effects such as gradient colors. this feature was not included in _gdiplus.vcx, but can also be accessed easily with a simple call to the flat api. a great part of the codes below that are related to the creation of the gradient brush is from bo durban.
To apply this to forms is really easy. add the codes below to the load, resize and destroy events of any form:
lcgradfile = addbs(sys(2023))+sys(2015)+".bmp"
clear resources (lcgradfile)
lnrgbcolor1 = rgb(60,30,180) && blue
* create gradient image
set classlib to home() + "ffc/_gdiplus.vcx" additive
* declare api
declare long gdipcreatelinebrushi in gdiplus.dll ;
string point1, string point2, ;
long color1, long color2, ;
long wrapmode, long @linegradient
* create a colorobject and store argb color values to variables
local loclr as gpcolor of home() + "ffc/_gdiplus.vcx"
local lncolor1, lncolor2
loclr = createobject("gpcolor")
loclr.foxrgb = lnrgbcolor1
lncolor1 = loclr.argb
loclr.foxrgb = rgb(255,255,255) && white
lncolor2 = loclr.argb
* create a bitmap
local lobmp as gpbitmap of home() + "ffc/_gdiplus.vcx"
lobmp = createobject("gpbitmap")
* get a bitmap graphics object
local logfx as gpgraphics of home() + "ffc/_gdiplus.vcx"
logfx = createobject("gpgraphics")
* get a gradient brush
local lobrush as gpbrush of home() + "ffc/_gdiplus.vcx"
local hbrush && brush handle
hbrush = 0
lncolor1, lncolor2, 0, @hbrush)
lobrush = createobject("gpbrush")
* fill the bitmap with our gradient
.stretch = 2
.width = thisform.width
.height = thisform.height
.picture = lcgradfile
.visible = .t.
thisform.imgbackground.width = thisform.width
thisform.imgbackground.height = thisform.height
clear resources (.ctempgradfile)
new GDI+ classes
The code i presented in the load event works pretty fine, but sounds really ugly, when comparing to what we will be able to do when the new sedna-x gdi+ classes will be released:
The code below will substitute all codes related to the creation of the gradient color in the load event. I just can't wait until the classes are finished ! Their work is really brilliant, and will add much more than a wrapper class !
* create gdi+ linear gradient image using xfc gdi+ classes from bo durban and craig boyd
local lobmp as xfcbitmap
local logfx as xfcgraphics
local lobrush as xfcbrush
lobmp = .bitmap.new(1, thisform.height)
logfx = .graphics.fromimage(lobmp)
lobrush = .drawing2d.lineargradientbrush.new( ;
.rectangle.new(0, 0, 1, thisform.height), ;
.color.fromrgb(lnrgbcolor1), .color.white, 1)
Related post: Gradient backgrounds in your forms with gdi+ part 2