Ownerdraw VCL grids not picking expected selected colour for VCL Style

309 views Asked by At

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

1

There are 1 answers

1
RRUZ On BEST ANSWER

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);