This one goes to Bernard Bout.
After reading this post check also: Gradient Backgrounds in your forms with GDI+ Part 2


GDI+ allows 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:
Load Event
LOCAL lcGradFile
lcGradFile = ADDBS(SYS(2023))+SYS(2015)+".bmp"
This.AddProperty("cTempGradFile",lcGradFile)
IF FILE(lcGradFile)
CLEAR RESOURCES (lcGradFile)
ENDIF
LOCAL lnRGBColor1
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")
loBmp.Create(1,Thisform.Height)
* Get a bitmap graphics object
LOCAL loGfx AS GpGraphics OF HOME() + "ffc/_gdiplus.vcx"
loGfx = CREATEOBJECT("gpGraphics")
loGfx.CreateFromImage(loBmp)
* Get a gradient brush
LOCAL loBrush as GpBrush OF HOME() + "ffc/_gdiplus.vcx"
LOCAL hBrush && Brush Handle
hBrush = 0
GdipCreateLineBrushI(BINTOC(0,"4rs")+BINTOC(0,"4rs"), ;
BINTOC(0,"4rs")+BINTOC(Thisform.Height,"4rs"), ;
lnColor1, lnColor2, 0, @hBrush)
loBrush = CREATEOBJECT("gpBrush")
loBrush.SetHandle(hBrush, .T.)
* Fill the bitmap with our gradient
loGfx.FillRectangle(loBrush,0,0,1,Thisform.Height)
loBmp.SaveToFile(lcGradFile,"image/bmp")
Thisform.AddObject("ImgBackGround","Image")
WITH Thisform.ImgBackGround
.Stretch = 2
.Width = Thisform.Width
.Height = Thisform.Height
.Picture = lcGradFile
.Visible = .T.
ENDWITH
RETURN
Resize Event
Thisform.ImgBackGround.Width = Thisform.Width
Thisform.ImgBackGround.Height = Thisform.Height
Destroy Event
WITH Thisform
IF FILE(.cTempGradFile)
CLEAR RESOURCES (.cTempGradFile)
ERASE (.cTempGradFile)
ENDIF
ENDWITH
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
DO LOCFILE("System.App")
LOCAL loBmp AS xfcBitmap
LOCAL loGfx AS xfcGraphics
LOCAL loBrush AS xfcBrush
WITH _Screen.System.Drawing
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)
loGfx.FillRectangle(loBrush, loBrush.Rectangle)
loBmp.Save(lcGradFile, .Imaging.ImageFormat.Bmp)
ENDWITH


Click to download the source code of this form example