Membuat Animasi Caption Bar Berjalan Menggunakan Delphi
بسم الله الرحمن الرحيم
Alhamdulillah, kembali saya mau berbagi ilmu dengan sahabat-sahabat, sederhana saja, ilmunya orang awwam. Tapi semoga bermanfaat, aamiin. Saya akan berbagi trik membuat Animasi Caption Bar pada form delphi, berikut screen shootnya
Langsung saja kita menuju coding nya,
1. Deklarasikan variabel dan konstanta berikut yang berwarna merah
var
Form1: TForm1;captionf: string;
lagi : boolean;
const
judul = 'Aplikasi Inventory';
implementation
{$R *.dfm}
2. Pada events FormOnCreate, ketik coding berikut
var
i:byte;begin
lagi := false;
for i:= 1 to Form1.Width do
begin
Insert(' ', captionf,1);
end;
captionf := captionf+judul;
end;
3. Tambahkan Objek TTimer yang ada pada tab komponen System, ubah properties Interval menjadi 500, double klik pada objek TTimer kemudian ketik coding berikut:
var
i:byte;begin
if lagi = false then
begin
Delete(captionf,1,1);
if length(captionf) = 0 then
begin
lagi := true;
end
end
else
begin
for i:= 1 to Form1.Width do
begin
Insert(' ', captionf,1);
end;
captionf := captionf+judul;
if length(captionf) = length(captionf) then
begin
lagi := false;
end
end;
Form1.Caption := captionf;
end;
4. Simpan dan jalankan program, bila benar maka Caption Bar akan terlihat berjalan,
5. Berikut coding lengkapnya
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, XPMan, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
Timer1: TTimer;
Button1: TButton;
RichEdit1: TRichEdit;
Button2: TButton;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
captionf: string;
lagi : boolean;
const
judul = 'Aplikasi Inventory';
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
i:byte;
begin
lagi := false;
for i:= 1 to Form1.Width do
begin
Insert(' ', captionf,1);
end;
captionf := captionf+judul;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
i:byte;
begin
if lagi = false then
begin
Delete(captionf,1,1);
if length(captionf) = 0 then
begin
lagi := true;
end
end
else
begin
for i:= 1 to Form1.Width do
begin
Insert(' ', captionf,1);
end;
captionf := captionf+judul;
if length(captionf) = length(captionf) then
begin
lagi := false;
end
end;
Form1.Caption := captionf;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
RichEdit1.SelectAll;
RichEdit1.CopyToClipboard;
ShowMessage('Sudah Disalin, silahkan di-paste aja');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Application.Terminate;
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, XPMan, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
Timer1: TTimer;
Button1: TButton;
RichEdit1: TRichEdit;
Button2: TButton;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
captionf: string;
lagi : boolean;
const
judul = 'Aplikasi Inventory';
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
i:byte;
begin
lagi := false;
for i:= 1 to Form1.Width do
begin
Insert(' ', captionf,1);
end;
captionf := captionf+judul;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
i:byte;
begin
if lagi = false then
begin
Delete(captionf,1,1);
if length(captionf) = 0 then
begin
lagi := true;
end
end
else
begin
for i:= 1 to Form1.Width do
begin
Insert(' ', captionf,1);
end;
captionf := captionf+judul;
if length(captionf) = length(captionf) then
begin
lagi := false;
end
end;
Form1.Caption := captionf;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
RichEdit1.SelectAll;
RichEdit1.CopyToClipboard;
ShowMessage('Sudah Disalin, silahkan di-paste aja');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Application.Terminate;
end;
end.
Hanya itu yang bisa saya jelaskan, terima kasih,
Wassalamu 'Alaikum Wr. Wb
Comments
Post a Comment
Selamat berkunjung di blog saya, terima kasih.