0

Our product uses an owner-draw grid (TStringGrid) - where we are drawing all off the grid. I am trying to make this respect the VCL style that is used by the application. Most of this works, but when i try and get the selected colour for the grid, then it either appears to be black (not great when the style being used is already dark), or a seemingly random gradient. Here is the code I am using to get the selected colour (it maybe that I am using the wrong element or ElementColor to get the expected colour).

    StyleServices.GetElementColor (StyleServices.GetElementDetails (tgCellSelected), ecFillColor, theColor);

Any help would be appreciated. Thanks

mmmm
  • 2,431
  • 2
  • 35
  • 56

1 Answers1

2

Not all the TElementColor (ecBorderColor, ecFillColor, ecTextColor, ..) are defined for all the possible TThemedElementDetails, So you must always check the boolean result returned by the GetElementColor function.

If the result is false means which the color is not defined. In your case the there is not a color value defined for the ecFillColor when the Element is tgCellSelected.

Try this sample, which uses the tgClassicCellSelected element instead and if not exist just use the HighLight color of the active VCL Style.

if not StyleServices.GetElementColor(StyleServices.GetElementDetails(tgClassicCellSelected), ecFillColor, AColor) then
 AColor := StyleServices.GetSystemColor(clHighlight);
RRUZ
  • 134,889
  • 20
  • 356
  • 483
  • I had experimented with setting it to every type of element, and had settled on the `tgFixedCellNormal` as you suggested. The fall back is a good it as well. Thanks (again) – mmmm Dec 23 '16 at 16:24