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 ?

NGLN
  • 43,011
  • 8
  • 105
  • 200
Mawg says reinstate Monica
  • 38,334
  • 103
  • 306
  • 551
  • 2
    It's `clHighlight`... see `Grids.pas`, method `TCustomGrid.Paint`, inner procedure `DrawCells` (in Delphi 2009). – TLama Oct 25 '12 at 01:20
  • @TLama Pelase post that as an answer and I will award. Thanks – Mawg says reinstate Monica Oct 25 '12 at 01:32
  • 4
    @TLama The color depends of the [DrawingStyle](http://docwiki.embarcadero.com/Libraries/XE3/en/Vcl.Grids.TCustomGrid.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 .... – RRUZ Oct 25 '12 at 01:37
  • @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... – TLama Oct 25 '12 at 01:52
  • 2
    @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. – Wouter van Nifterick Oct 25 '12 at 01:59
  • @RRUZ, TLama but your both probably forgotten VCL Skins ? :-) – Arioch 'The Oct 25 '12 at 12:10

1 Answers1

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.

RRUZ
  • 134,889
  • 20
  • 356
  • 483