Foxite.COM Community Weblog

Foxite.COM Community Weblog - free weblog service for the Visual FoxPro Community.
Welcome to Foxite.COM Community Weblog Sign in | Join | Help
in
Home Blogs Forum Photos Forum Archives

VFP IMAGING



NEW GRADIENT BACKGROUND CLASS

After all those posts discussing and showing how to create gradient backgrounds for VFP forms, I decided to create a simple but powerful class to ease this process.

The GRADBACKGROUNDS class is stored inside the GRADIENTOBJECTS.VCX, the class that I published last year that converts any CommandButton, Graphical CheckBox or Graphical OptionBox.

Just drop an instance of the class GradBackgrounds to any Form, Container or Pageframe and set some properties to obtain the gradient effects shown below.

All the Background images are created using GDI+, but with no helper class, because I wanted to obtain the best performance possible.

 

Properties

GradientMode - Numeric, from 1 to 4, determines the gradient type to be created
1 - Horizontal   2 - Vertical   3 - diagonal 1   4 - diagonal 2 using linear gradient
brushes with 2 colors

BackColor1 - Numeric, the RGB value of the starting color of the gradient background

BackColor2 - Numeric, the RGB value of the destination color of the gradient background

ReduceColorLevel - Numeric, automatically sets the destination color of the gradient (backColor2) ranging from 0 (no change) to 100 (white). If left to .F., then no change is applied and the original values of BackColor2 and SelBackColor2 will be used.

UpdateTabColor - In the case of a PageFrame, sets "themes" off to allow the tab background to be in the same color of the gradient


Method

Update - Updates the gradient if you change any of the above properties

 

Form using GradientMode = 1

 

Form using GradientMode = 2

 

Form using GradientMode = 3

 

Form using GradientMode = 4

 

 

PLAYING WITH PAGEFRAMES

As containers, PageFrames allow to set a Picture property. We can also obtain a cool effect changing the Tab colors to use the same color of the gradient picture.

To make it work, drop an instance of the class inside EVERY page thet you want to convert to Gradient. When inside a pageframe, the property gradient mode becomes automatic, and works according to the TabOrientation property of the PageFrame.

 

 

The gradient adapts to the tabOrientation property of the PageFrame

 

 

IMPORTANT NOTES

To make the class work inside a container, don't forget to set its backStyle to 1 - Opaque
DOnt forget to set the BackStyle property of your labels to 0 - Transparent
 

 

VFP9 IS COOL !

In this version of the class I started using some scripts to ease the manipulation of the properties. For example, now if you double click on the BackColor1 Property, the color picker opens automatically, to allow you to choose your color. Thanks to the great book "What's new in Nine", and some great tips from Fabio Lunardon and Tamar Granor.

 

DISCLAIMER

This class is totally free. The information provided on this page and the source code related to this article comes without any warranty whatsoever. Use it at your own risk.

 

SOME RELATED LINKS

Gradient Backgrounds in your forms with GDI+

Gradient Command Buttons with GDI+

GRADIENT OBJECTS WITH GDI+ REVISITED

  

As always, if you have any suggestion, or find any bugs please tell me !


Click here to download the latest version of the Gradient objects class.

or Here (mirror)

Published Friday, February 16, 2007 3:20 AM by cesarchalom
Filed Under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Ailsom said:

Very Good, Mestre !
February 16, 2007 12:24 PM
 

Edward Dantas said:

Parabens Cesar.
Sempre melhorando o que já era ótimo.
February 16, 2007 5:54 PM
 

Dan said:

OMG, I feel in heaven ... these are just great
Cesar you're great man ... and FoxPro just ROOOOCKS
February 16, 2007 6:36 PM
 

Bernard Bout said:

Good Stuff as always Cesar.

Have you solved the problem of loading these images without writing to a file?
February 17, 2007 3:38 AM
 

Bernard Bout said:

Another thought.

Could we use

GdipSaveImageToStream

to write to the USER field in the class or to a blob field in memory?

Calvin Hsia has an article about this which may help at:

http://blogs.msdn.com/calvin_hsia/archive/2006/02/17/534529.aspx

Cheers 

Bernard
Off to OzFox next week.

Hey Bernard,

Thanks for the feedback. Yep ! I know that article, very inspiring indeed. That will be the probable best way to do it. Calvin needed to create a DLL that needs to be registered using "regsvr". I hope to prepare a sample using it. One of the few things that is still missing in GdiPlusX is the Stream management class. As Bo Durban said, this will probably need a helper FLL for that. In that article, Calvin gives some details about why that is needed. So, I'll leave this part for Bo. As soon as this class is finished, we'll be able to do some great new "miracles" with GDI+.

Regards

Cesar

February 17, 2007 3:47 AM
 

Olivier Hamou said:

hi cesar,

I want to use your class to make a similar toolbar office 2003 (blue gradient)
But i don't reproduce the same gradient.
Before i could make, but with the class, the color is too white.
I think to come the property ReduceColorLevel, cause it's not possible to put the value 0.

i want to make a similar background that the OutlookBar guy with the new gradient background

Thank's for all
Olivier

before i use the old code.

** Create a colorObject and store ARGB color values to variables
LOCAL loClr as GpColor OF HOME() + "classes/_gdiplus.vcx"


LOCAL lnColor1, lnColor2
loClr = CREATEOBJECT("gpColor")
loClr.FoxRGB = lnRGBColor1
lnColor1 = loClr.ARGB
loClr.FoxRGB = lnRGBColor2
lnColor2 = loClr.ARGB

** Create a bitmap
LOCAL loBmp as GpBitmap OF HOME() + "classes/_gdiplus.vcx"
loBmp = CREATEOBJECT("gpBitmap")
loBmp.Create(lnWidth, lnHeight)

** Get a bitmab graphics object
LOCAL loGfx as GpGraphics OF HOME() + "classes/_gdiplus.vcx"
loGfx = CREATEOBJECT("gpGraphics")
loGfx.CreateFromImage(loBmp)

** Declare API
DECLARE Long GdipCreateLineBrushI IN "gdiplus.dll" ;
  String point1, String point2, ;
  Long color1, Long color2, ;
  Long wrapMode, Long @lineGradient

** Get a gradient brush
LOCAL loBrush as GpBrush OF HOME() + "classes/_gdiplus.vcx"
LOCAL hBrush && Brush Handle
hBrush = 0
GdipCreateLineBrushI(BINTOC(x1,"4rs")+BINTOC(y1,"4rs"), ;
     BINTOC(x2,"4rs")+BINTOC(y2,"4rs"), ;
     lnColor1, lnColor2, 0, @hBrush)
loBrush = CREATEOBJECT("gpBrush")
loBrush.SetHandle(hBrush, .T.)


** Fill the bitmap with our gradient
loGfx.FillRectangle(loBrush,0,0,lnWidth, lnHeight)
loBmp.SaveToFile(.cTempGradFile,"image/bmp")

 

Hey Olivier,

For the 2nd color to become a non white, you need to store a .F. to the property "ReduceColorLevel". Please test it, and tell me how it works. In the samples, I added some forms that create non white ending colors, you may want to check there too.

Hope this helps !

Saltutations,

Cesar

May 21, 2007 6:44 PM
 

Mario Cesar Hernandez said:

Hi Cesar;
I'm using your class, but i have some troubles,whit one form
this form don't showme the gradient, in the form and container
in the container   the backstyle =1 and my labels is transparent
please help me

best reggards and thaks for all

pd. Una disculpa por mi ingles

Hola Mario,

Perdon por tardar tanto para te contestar. Puedes enviarme tu informe ? Las muestras que vienen junto con "GradObjects" funcionan correctamente ?

Probablemente, tienes que ajustar alguna de las propiedades de la clase. Puedes intentar de "Paste" la clase directamente de una de las muestras.

Saludos

Cesar

September 11, 2007 8:12 PM
 

Vivek Deodhar said:

Great! I have successfully implemented this in my application and it it looks now much much better than before. Thanks.

I have observed that If I drag an instance into a container and add command buttons in this container, they are all getting the effect, but if I add any olecontrol (I use menubutton control), it is not affected. Can I do that?

Vivek

Hi Vivek,

I'm glad to know you find it helpful. GradObjects depends on the "Picture" property of the objects from the container. Maybe we can make it work, if your control has the "Picture" property, with some small adjustments in the source code of GradObjects.

Please create a sample form with your ActiveX, and send to : vfpimaging at hotmail dot com

Regards

Cesar

April 16, 2008 6:52 AM

What do you think?

(required) 
(optional)
(required)