Ver Mensaje Individual
  #1  
Antiguo 03-03-2023
dani36652 dani36652 is offline
Miembro
 
Registrado: abr 2019
Posts: 55
Reputación: 6
dani36652 Va camino a la fama
Lightbulb (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.
Responder Con Cita