Frequently Asked Component Specific Questions

Options

Display all FAQ items

Search FAQ items:


Displaying items 1 to 1 of 1, page 1 of 1

<< previous next >>

TMS FlexCel for VCL & FMX
Changing the background color of a cell in FlexCel

It can be confusing that the code to change the background of a cell is something like:

fmt1.FillPattern.Pattern := TFlxPatternStyle.Solid;
fmt1.FillPattern.FgColor := $00BCE4D8;

Why are we changing the FgColor instead of the BgColor in order to change the background color? And why does changing BgColor has no effect?

It can be a little confusing because of the names (which are the same the Excel documentation uses), but you need to understand that both FgColor and BgColor refer to the background color of a cell, and that’s why both are properties of the FillPattern. The foreground color is changed by changing the font color.

The thing is, in Excel, cells don’t need to have a solid fill, they can have a pattern fill. For example, here you have a “grid” pattern, where the foreground of the pattern is red, and the background of the pattern is yellow:


So, in FlexCel “FgColor” and “BgColor” both refer to the fill of the cell (never the foreground which as said is Font.Color). For the special case of Pattern = Solid (what we use in the 99.999% of the cases), then you set the FillPattern.Pattern to Solid, and BgColor doesn’t really matters. You can think of “Solid” as a pattern where everything is covered by the foreground color. The BgColor is still there, but not visible because FgColor covers all. If you set any other pattern than solid, you’ll see it more clearly.