For this example we use three TButtons and a TImage component.
First we create a .res file using Borlands Image Editor.
In Image Editor:
Go to File | New | Resource File.
Right-click in the Untitled1.res window
and choose New | Icon.
Click OK in the Icon Properties dialog
that pops-up.
Double-click on the Icon1 item in the
tree list.
Draw your icon.
Now close the Icon1 (Untitled1.res) dialog.
Add another icon.
Right-click on the Icon1 item in the tree
list and choose Rename.
Rename Icon1 to IconOne and then change
Icon2 to IconTwo.
Go to File | Save.
Save your resource file as loadicon.res
in
the directory (folder) where you will save your Project in Delphi.
Start a new Project.
Add three TButton components and a TImage component to your Form.
Add {$R loadicon.res} next to {$R *.DFM} after the implementation.
Add this code to Button1's OnClick event:
procedure TForm1.Button1Click(Sender: TObject);
begin
Application.Icon.Handle
:= LoadIcon(hInstance, 'ICONONE');
Image1.Picture.Icon.Handle
:= LoadIcon(hInstance, 'ICONONE');
end;
For Button2's OnClick event add this code:
procedure TForm1.Button2Click(Sender: TObject);
begin
Application.Icon.Handle
:= LoadIcon(hInstance, 'ICONTWO');
Image1.Picture.Icon.Handle
:= LoadIcon(hInstance, 'ICONTWO');
end;
And for the last button, Button3, add this code:
procedure TForm1.Button3Click(Sender: TObject);
begin
Image1.Picture.Assign(nil);
// Clear the image
end;
Run your Application and click on the Buttons.
unit Unit1; interface uses
type
var Form1: TForm1;
procedure TForm1.Button1Click(Sender: TObject);
procedure TForm1.Button2Click(Sender: TObject);
procedure TForm1.Button3Click(Sender: TObject);
end.
|