Zoom the content of a Stringgrid

Zoom the content of a Stringgrid

// Zoom the content of a StringGrid


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Grids, StdCtrls, Buttons;

type
  TForm1 = class(TForm)
    grid: TStringGrid;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
  private
    procedure gridZoom(FFact: Real);
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.gridZoom(FFact: Real);
var
  x: Integer;
begin
  for x := 0 to grid.colcount - 1 do
    grid.colwidths[x] := round(grid.colwidths[x] * FFact);

  for x := 0 to grid.RowCount - 1 do
    grid.rowheights[x] := round(grid.rowheights[x] * FFact);

  grid.Font.Size := round(grid.rowheights[0] * 0.65);
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
     gridZoom(1.1);
end;

procedure TForm1.BitBtn2Click(Sender: TObject);
begin
  gridZoom(0.9);
end;

end.