Recent

Author Topic: [SOLVED] Change a TLable Color, how to?  (Read 1692 times)

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 437
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
[SOLVED] Change a TLable Color, how to?
« on: November 23, 2023, 04:47:15 pm »
Probably simple but can't figure a way to program this. Basically, have a Procedure that rebuilds/creates the system database. I have a Progress Bar and figured out how to make it PROGRESS, LoL!  But the TLabel above it Caption is assigned Progress ... as the progressbar's position is incremented by values of 10 to 100.
At the end, I want to change the Label caption to Completed! but to green which do that but also flashing Green.  So, is there a way instead of rewriting a for...loop just erasing the caption from Completed to blank then back to Completed! over and over in the loop? I like special affects! Maybe also add a buzz or the sound of a jet landing!
« Last Edit: November 26, 2023, 10:17:30 pm by 1HuntnMan »

Handoko

  • Hero Member
  • *****
  • Posts: 5524
  • My goal: build my own game engine using Lazarus
Re: Change a TLable Color, how to?
« Reply #1 on: November 23, 2023, 06:06:41 pm »
Did you mean something like this:

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, ComCtrls, StdCtrls, ExtCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     Label1: TLabel;
  17.     ProgressBar1: TProgressBar;
  18.     Timer1: TTimer;
  19.     procedure Button1Click(Sender: TObject);
  20.     procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
  21.     procedure FormCreate(Sender: TObject);
  22.     procedure Timer1Timer(Sender: TObject);
  23.   end;
  24.  
  25. var
  26.   Form1: TForm1;
  27.  
  28. implementation
  29.  
  30. {$R *.lfm}
  31.  
  32. { TForm1 }
  33.  
  34. procedure TForm1.Button1Click(Sender: TObject);
  35. const
  36.   MaxCount = 1000;
  37.   Delay    = 8;
  38. var
  39.   i: Integer;
  40. begin
  41.   Button1.Enabled   := False;
  42.   Timer1.Enabled    := False;
  43.   Label1.Font.Color := clBlack;
  44.   i := 0;
  45.   repeat
  46.     Inc(i);
  47.     ProgressBar1.Position := i div 10;
  48.     Label1.Caption := 'Progress : ' + (i/MaxCount * 100).ToString + '%';
  49.     Sleep(Delay);
  50.     Application.ProcessMessages;
  51.   until i >= MaxCount;
  52.   Label1.Caption  := 'Process completed!';
  53.   Timer1.Enabled  := True;
  54.   Button1.Enabled := True;
  55. end;
  56.  
  57. procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
  58. begin
  59.   Halt;
  60. end;
  61.  
  62. procedure TForm1.FormCreate(Sender: TObject);
  63. begin
  64.   ProgressBar1.Smooth := True;
  65.   Timer1.Enabled      := False;
  66.   Timer1.Interval     := 30;
  67. end;
  68.  
  69. procedure TForm1.Timer1Timer(Sender: TObject);
  70. const
  71.   Brightness: Byte = 255;
  72. begin
  73.   case Brightness > 50 of
  74.     True:  Dec(Brightness, 5);
  75.     False: Brightness := 255;
  76.   end;
  77.   Label1.Font.Color := RGBToColor(0, Brightness, 0);
  78. end;
  79.  
  80. end.

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 437
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: Change a TLable Color, how to?
« Reply #2 on: November 23, 2023, 07:09:43 pm »
Ok Handoko, thanks! That's more than I expected but taught me a different way to do what I programmed! Back to revamping the way I programmed it.  I just updated the ProgressBar's position through out the procedure of rebuilding the tables the way you did it and so on.

 

TinyPortal © 2005-2018