bgColor vs fgColor

Hi Adrian

I'm curious to understand the difference between these. When I load my grid or set the cell background colour I have to use fgColor, e.g. in ALayout.Fill.Color := format.FillPattern.FgColor.ToColor(FExcelFile)

The same goes for setting the colour from code, e.g. fmt.FillPattern.FgColor := clr.FromArgb(rgbColor.R, rgbColor.G, rgbColor.B, 0);

If I use bgColor the cells are filled black - i.e. the foreground (or font) colour. I see that the help file says TFlxFillPattern controls the fill pattern and colour for the background. So fgColor is the foreground of the background? When would I use bgColor?

Thanks, Bob


The names "FgColor" and "BgColor" can be confusing, if I had to choose them today I would use different names. But when I did it more than a decade ago, I just followed the names Excel itself used in its documentation.

It works like this: In Excel a "background" can have more than one color. I guess nobody really uses those backgrounds today, but I remember back the days when I first saw them in quattro pro (am I so old?), they looked cool, probably because you couldn't make much with those apps, so anything looked cool.

In this example, you have a cell with a background of stripes of  blue (bgcolor) and red (fgcolor):

So this is the deal: Both FgColor and BgColor apply to the "Background Color" of the cell (and that's why so many people is confused with changing the FgColor to change the background of the cell, but that's how Excel works). If you have a pattern in a cell (TFlxFillPattern isn't solid), then BgColor is the background of the pattern, and FgColor is the foreground of the pattern (in the example above, FgColor is the color of the red stripes over the blue background). If you had a "dots" pattern, then FgColor would be the color of the dots. But if you have a Solid pattern (like everyone has), then it works as if you have a background of BgColor, completely covered by a rectangle of FgColor. So what color BgColor has doesn't matter, you only see FgColor which completely covers the pattern. But this is only for Solid patterns, other patterns use both colors. 

Note that you also can have gradients on cells, a feature also nobody seems to use but which we support fully, including in APIMate. In the case of a gradient, the "background color of the cell" is composed by many colors, but that doesn't use Fg/BgColor.