Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Trucos (https://www.clubdelphi.com/foros/forumdisplay.php?f=52)
-   -   (FMX) cambiar color del Header del StringGrid (https://www.clubdelphi.com/foros/showthread.php?t=96143)

dani36652 03-03-2023 18:49:45

(FMX) cambiar color del Header del StringGrid
 
Hola colegas, les comparto el día de hoy un procedimiento el cual sirve para cambiar el color del Header del stringGrid en FireMonkey

Código Delphi [-]
procedure ColorFondoHeaderStringGrid(ObjetoGrid: TStringGrid);
var
  i: integer;
  Header: THeader;
  RecColor: TRectangle;
  Texto: TText;
  Obj: TFmxObject;
  Headerlbl:TLabel;
begin
  Header := THeader(ObjetoGrid.FindStyleResource('Header'));
  if Assigned(Header) then
  begin
    for i := 0 to ObjetoGrid.ColumnCount do
    // NOTA: ColumnCount-1 pinta solo las que ocupa el grid como tal
    // y ColumnCount pinta las que se ocupan más el resto del Header
    begin
      Obj := Header.Items[i];
      if Assigned(Obj) then
      begin
        RecColor := TRectangle.Create(Obj);
        Obj.AddObject(RecColor);
        RecColor.Fill.Kind := TBrushKind.Solid;
        RecColor.Fill.Color:= $FF353784;
        RecColor.Stroke.Color := $FF353784;
        RecColor.Align := TAlignLayout.Contents;
        RecColor.HitTest := False;
        RecColor.SendToBack;
        if Assigned(Obj.FindStyleResource('Text')) then
        begin
        //Nota: Se sustituyen los TText de los Headers ya que en Android al hacer Scrolling a los lados
        // Desaparecían todos los headers
          Texto := TText(Header.Items[i].FindStyleResource('Text'));
          Texto.Visible:= False;
          Headerlbl:= TLabel.Create(RecColor);
          Headerlbl.Parent:= RecColor;
          Headerlbl.Align:= TAlignLayout.Client;
          Headerlbl.HitTest:= False;
          Headerlbl.StyledSettings:= [];
          Headerlbl.Text:= Texto.Text;
          Headerlbl.FontColor:= TAlphaColors.White;
          Headerlbl.Font.Size:= ObjetoGrid.TextSettings.Font.Size;
          Headerlbl.TextAlign:= TTextAlign.Center;
        end;
      end;
    end;
  end;
end;

Espero y les sea de ayuda saludos.

Casimiro Notevi 03-03-2023 19:17:47

^\||/^\||/^\||/


La franja horaria es GMT +2. Ahora son las 16:01:06.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi