Advertisement
jpfassis

StringGrid Aligning Title - Delphi in Delphi

May 2nd, 2020
1,342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.37 KB | None | 0 0
  1. //StringGrid Aligning Title - Delphi
  2.  
  3. procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  4.   Rect: TRect; State: TGridDrawState);
  5. var
  6.   LStrCell: string;
  7.   LRect: TRect;
  8. begin
  9.  
  10.   if ARoW = 0 then begin
  11.     //pega o string da celula
  12.     LStrCell := StringGrid1.Cells[ACol, ARow]; // grab cell text
  13.     //muda cor e tamanho da fonte
  14.     StringGrid1.Canvas.Font.Color:=clwhite;
  15.     StringGrid1.Canvas.Font.Size:=12;
  16.     //muda a cor da celula
  17.     StringGrid1.Canvas.Brush.Color:=clblue;
  18.     StringGrid1.Canvas.FillRect(Rect);
  19.     LRect := Rect;
  20.     //ajusta o topo
  21.     LRect.Top := LRect.Top + 2;
  22.     //ajusta Left
  23.     LRect.Left := LRect.Left + 3;
  24.     //ajusta Left
  25.     LRect.Right := LRect.Right - 3;
  26.  
  27.       case aCol of
  28.         // desenha o texto alinhado conforme desejado
  29.         0:
  30.         DrawText(StringGrid1.Canvas.Handle, PChar(LStrCell), Length(LStrCell), LRect, DT_LEFT);
  31.         1:
  32.         DrawText(StringGrid1.Canvas.Handle, PChar(LStrCell), Length(LStrCell), LRect, DT_CENTER);
  33.         2:
  34.         DrawText(StringGrid1.Canvas.Handle, PChar(LStrCell), Length(LStrCell), LRect, DT_RIGHT);
  35.         3:
  36.         DrawText(StringGrid1.Canvas.Handle, PChar(LStrCell), Length(LStrCell), LRect, DT_CENTER);
  37.         4:
  38.         DrawText(StringGrid1.Canvas.Handle, PChar(LStrCell), Length(LStrCell), LRect, DT_LEFT);
  39.       end;
  40.  
  41.  
  42.   end;
  43.  
  44. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement