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

1

6

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 ?

Noetic answered 25/10, 2012 at 1:15 Comment(6)
It's clHighlight... see Grids.pas, method TCustomGrid.Paint, inner procedure DrawCells (in Delphi 2009).Icbm
@Icbm Pelase post that as an answer and I will award. ThanksNoetic
@Icbm The color depends of the DrawingStyle property of the TStringGrid, for gdsClassic use clHighlight, for gdsGradient use StyleServices.GetSystemColor(clHighlight) ,for gdsThemed with vcl styles StyleServices.GetStyleColor(scGrid) and so on ....Sulfate
@RRUZ, d'oh, you're right, I forgot that Emba made the string grid cool that way (I have just that boring, non themed SG in my Delphi 2009 :-) And this question is for XE2 I guess. Taking back my comment...Icbm
@RRUZ, TLama: Any answer that will be given will be along the lines of what you two just wrote in your comments, so just post it as an answer that can be up-voted and accepted.Zed
@RRUZ, TLama but your both probably forgotten VCL Skins ? :-)Essy
S
11

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.

Sulfate answered 25/10, 2012 at 2:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.