TApplicationIcon (Delphi)
Description
The following code allows you to use a dialog box to redefine the icon for the application at run time. When you click Button1, OpenDialog1 executes and you specify an icon file name. The Icon is then assigned to the application. At run time, click Button1 to select the icon, then minimize the application to see the icon.
Code
procedure TForm1.Button1Click(Sender: TObject);
var
Done: Boolean;
filenamestring : String;
begin
OpenPictureDialog1.DefaultExt := GraphicExtension(TIcon);
filenamestring := GraphicFileMask(TIcon);
OpenPictureDialog1.FileName := filenamestring;
OpenPictureDialog1.Filter := GraphicFilter(TIcon);
OpenPictureDialog1.Options := [ ofFileMustExist, ofHideReadOnly, ofNoChangeDir ];
Done := False;
while not Done do
begin
if OpenPictureDialog1.Execute then
begin
if not (ofExtensionDifferent in OpenPictureDialog1.Options) then
begin
Application.Icon.LoadFromFile(OpenPictureDialog1.FileName);
Done := True;
end
else
// OpenPictureDialog1.Options := OpenPictureDialog1.Options - ofExtensionDifferent;
end
else { User cancelled }
Done := True;
end;
end;
Uses
- Vcl.Forms.TApplication.Icon ( fr | de | ja )
- Vcl.Dialogs.TOpenDialog.DefaultExt ( fr | de | ja )
- Vcl.Dialogs.TOpenDialog.FileName ( fr | de | ja )
- Vcl.Dialogs.TOpenDialog.Filter ( fr | de | ja )
- Vcl.Dialogs.TOpenDialog.Options ( fr | de | ja )
- Vcl.Dialogs.TOpenDialog.Execute ( fr | de | ja )
- Vcl.Graphics.GraphicFileMask ( fr | de | ja )
- Vcl.Dialogs.TOpenOptions ( fr | de | ja )