In my post this time I will share to you about menu, submenu and timer on Delphi Programming Language.
1.There is two types of menu, which main menu and pop-up menu.
Main menu is one of the components contained in Delphi palette. With a menu we can call, save, and run the program, remove program, etc. Menu helps us to run commands much easier. Delphi menu designer allow us to add a menu to the form. To create a main menu all we have to do is click the icon on the Delphi palette standard tab. Main menu usually located in the upper left corner of an application, such as file , insert, about, help, etc, that we usually see in almost every application.
pop up menu is a menu that appears when users right click on a form or on a component on Delphi
2. SubMenu
Submenu is an additional component that is used to save space for the additional options from the menu. Some applications have a drop down menu list that appears on the right side of a menu items.
Here's an example program using the menu:
The program above uses 2 forms, This is first form code list :
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Timer1: TTimer;
Label1: TLabel;
MainMenu1: TMainMenu;
Menu1: TMenuItem;
form21: TMenuItem;
exit1: TMenuItem;
color1: TMenuItem;
Hijau1: TMenuItem;
Biru1: TMenuItem;
Merah1: TMenuItem;
Default1: TMenuItem;
procedure Timer1Timer(Sender: TObject);
procedure form21Click(Sender: TObject);
procedure exit1Click(Sender: TObject);
procedure Hijau1Click(Sender: TObject);
procedure Biru1Click(Sender: TObject);
procedure Merah1Click(Sender: TObject);
procedure Default1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if label1.left=1 then label1.left:=50;
label1.left:=label1.left-1;
end;
procedure TForm1.form21Click(Sender: TObject);
begin
form1.Hide;
form2.show;
end;
procedure TForm1.exit1Click(Sender: TObject);
begin
application.terminate;
end;
procedure TForm1.Hijau1Click(Sender: TObject);
begin
label1.Font.Color:=clgreen;
end;
procedure TForm1.Biru1Click(Sender: TObject);
begin
label1.Font.Color:=clblue;
end;
procedure TForm1.Merah1Click(Sender: TObject);
begin
label1.font.Color:=clred;
end;
procedure TForm1.Default1Click(Sender: TObject);
begin
label1.font.color:=clblack;
end;
end.
This is the second form code list :
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm2 = class(TForm)
Button1: TButton;
Timer1: TTimer;
Label1: TLabel;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
uses Unit1;
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
begin
application.terminate;
end;
procedure TForm2.Timer1Timer(Sender: TObject);
begin
label1.caption:=formatdatetime('"time : "hh:mm:ss',now)+chr(13)+formatdatetime('"date : "dd/mm/yyyy',now);
end;
procedure TForm2.Button2Click(Sender: TObject);
begin
form2.Hide;
form1.show;
end;
end.
TO DOWNLOAD THE PROGRAM IN .exe CLICK HERE
If your antivirus detect this as virus just ignore it because it's save
1.There is two types of menu, which main menu and pop-up menu.
Main menu is one of the components contained in Delphi palette. With a menu we can call, save, and run the program, remove program, etc. Menu helps us to run commands much easier. Delphi menu designer allow us to add a menu to the form. To create a main menu all we have to do is click the icon on the Delphi palette standard tab. Main menu usually located in the upper left corner of an application, such as file , insert, about, help, etc, that we usually see in almost every application.
pop up menu is a menu that appears when users right click on a form or on a component on Delphi
2. SubMenu
Submenu is an additional component that is used to save space for the additional options from the menu. Some applications have a drop down menu list that appears on the right side of a menu items.
Here's an example program using the menu:
The program above uses 2 forms, This is first form code list :
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Timer1: TTimer;
Label1: TLabel;
MainMenu1: TMainMenu;
Menu1: TMenuItem;
form21: TMenuItem;
exit1: TMenuItem;
color1: TMenuItem;
Hijau1: TMenuItem;
Biru1: TMenuItem;
Merah1: TMenuItem;
Default1: TMenuItem;
procedure Timer1Timer(Sender: TObject);
procedure form21Click(Sender: TObject);
procedure exit1Click(Sender: TObject);
procedure Hijau1Click(Sender: TObject);
procedure Biru1Click(Sender: TObject);
procedure Merah1Click(Sender: TObject);
procedure Default1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if label1.left=1 then label1.left:=50;
label1.left:=label1.left-1;
end;
procedure TForm1.form21Click(Sender: TObject);
begin
form1.Hide;
form2.show;
end;
procedure TForm1.exit1Click(Sender: TObject);
begin
application.terminate;
end;
procedure TForm1.Hijau1Click(Sender: TObject);
begin
label1.Font.Color:=clgreen;
end;
procedure TForm1.Biru1Click(Sender: TObject);
begin
label1.Font.Color:=clblue;
end;
procedure TForm1.Merah1Click(Sender: TObject);
begin
label1.font.Color:=clred;
end;
procedure TForm1.Default1Click(Sender: TObject);
begin
label1.font.color:=clblack;
end;
end.
This is the second form code list :
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm2 = class(TForm)
Button1: TButton;
Timer1: TTimer;
Label1: TLabel;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
uses Unit1;
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
begin
application.terminate;
end;
procedure TForm2.Timer1Timer(Sender: TObject);
begin
label1.caption:=formatdatetime('"time : "hh:mm:ss',now)+chr(13)+formatdatetime('"date : "dd/mm/yyyy',now);
end;
procedure TForm2.Button2Click(Sender: TObject);
begin
form2.Hide;
form1.show;
end;
end.
TO DOWNLOAD THE PROGRAM IN .exe CLICK HERE
If your antivirus detect this as virus just ignore it because it's save