Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am overriding OnDrawCell for a string grid. In certain circumstance, I want to use the normal TColor that is used for the selected row when the system does the drawing (no OnDrawCell).

Which colo(u)r is that? clXXX ?

like image 630
Mawg says reinstate Monica Avatar asked Oct 25 '12 01:10

Mawg says reinstate Monica


1 Answers

Before of Delphi 2010 you can use the clHighlight color.

In Delphi 2010 the TStringGrid, TDrawGrid and TDBGrid components now have a DrawingStyle property and depending of this value (gdsClassic, gdsGradient, gdsThemed) you must calculate the color on this way.

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 the DrawElement method of the TCustomStyleServices

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

In Delphi XE2 (and XE3) with the introduction of the vcl styles you must use the same of the above but checking if the current style is a "custom style" (vcl style)

1.for gdsGradient use the GradientFillCanvas method calculating the colors of the gradient on 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 check a sample of how the VCL draw a selected (highlighted) cell/row try the implementation of the TCustomGrid.DrawCellHighlight method.

like image 104
RRUZ Avatar answered Sep 20 '22 22:09

RRUZ