Recent

Author Topic: Unable to create a cycle of TButton size changes  (Read 1363 times)

c0rbe

  • Newbie
  • Posts: 2
Unable to create a cycle of TButton size changes
« on: August 20, 2017, 04:39:03 pm »
Im new to this but the logic seems right, would appreciate any help.
I'm trying to make the Button get smaller twice and then finally return back to it's original size.

procedure TForm1.Button1Click(Sender: TObject);
begin
          if Button1.tag = 0 then
  begin
    Button1.width := 200;
    Button1.height := 45;
    Button1.caption := 'Smaller Button';
    Button1.tag := 1;
  end;
          if Button1.tag = 1 then
  begin
    Button1.width := 150;
    Button1.height := 30;
    Button1.caption := 'Even Smaller Button';
    Button1.tag := 2;
  end;
          if Button1.tag = 2 then
  begin
    Button1.width := 280;
    Button1.height := 64;
    Button1.caption := 'Big Again';
    Button1.tag := 0;

end;

Thanks in advance!

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Unable to create a cycle of TButton size changes
« Reply #1 on: August 20, 2017, 05:04:41 pm »
Try
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2.  
  3.    procedure AlterButton(w, h, t: Integer; const aCaption: string);
  4.    begin
  5.      with Button1 do begin
  6.        SetBounds(Left, Top, w, h);
  7.        Tag:=t;
  8.        Caption:=aCaption;
  9.      end;
  10.    end;
  11.  
  12. begin
  13.   with Button1 do begin
  14.     if AutoSize then
  15.       AutoSize:=False;
  16.     case Tag of
  17.       0: AlterButton(200, 45, 1, 'smaller button');
  18.       1: AlterButton(150, 30, 2, 'even smaller');
  19.       2: AlterButton(280, 64, 0, 'big again');
  20.     end;
  21.   end;
  22. end;

c0rbe

  • Newbie
  • Posts: 2
Re: Unable to create a cycle of TButton size changes
« Reply #2 on: August 20, 2017, 05:07:14 pm »
Thank you very much!

 

TinyPortal © 2005-2018