What is the normal colo (u) r of the selected stringgrid row?

I am redefining OnDrawCell for a string grid. In some cases, I want to use the usual TColor , which is used for the selected line when the system is drawing (no OnDrawCell ).

What colo (u) r is this? clXXX?

+6
source share
1 answer

Prior to Delphi 2010, you can use clHighlight color.

In Delphi 2010, the TStringGrid, TDrawGrid, and TDBGrid components now have the DrawingStyle property and depending on this value (gdsClassic, gdsGradient, gdsThemed) you should calculate the color along this path.

1.for gdsClassic use clHighlight ;

2.for gdsGradient use the GradientFillCanvas method

 GradientFillCanvas(Canvas, GetShadowColor(clHighlight, 45), GetShadowColor(clHighlight, 10), LRect, gdVertical); 

3.for gdsThemed call DrawElement TCustomStyleServices method

 StyleServices.DrawElement(Canvas.Handle, StyleServices.GetElementDetails(tgCellSelected), LRect, ARect); 

In Delphi XE2 (and XE3) with the introduction of vcl styles, you should use the same from above, but check if the current style is a โ€œcustom styleโ€ (vcl style)

1.for gdsGradient use the GradientFillCanvas method, which computes the colors of the gradient in this way

 StyleServices.GetElementColor(StyleServices.GetElementDetails(tgGradientCellRowSelectedRight), ecGradientColor1, StartColor); //StartColor is a TColor variable StyleServices.GetElementColor(StyleServices.GetElementDetails(tgGradientCellRowSelectedRight), ecGradientColor2, EndColor);//EndColor is a TColor variable 

2.for gdsClassic

 StyleServices.GetElementColor(StyleServices.GetElementDetails(tgClassicCellRowSelectedRight), ecFillColor, LColor); //LColor is a TColor variable 

If you want to check a sample of how VCL draws the selected (selected) cell / row, try implementing the TCustomGrid.DrawCellHighlight method.

+11
source

All Articles