Recent

Author Topic: How can I display the built-in icons on the buttons?  (Read 1527 times)

iruanpan

  • New Member
  • *
  • Posts: 10
How can I display the built-in icons on the buttons?
« on: January 28, 2024, 06:26:08 am »
Excuse me. How can I display the built-in icons on the buttons?

The application was compiled with an icon collection. Can I display one of these icons on a button component?

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: How can I display the built-in icons on the buttons?
« Reply #1 on: January 28, 2024, 07:18:27 am »
You need to place Icons in the RT_ICON section and call my method
image1 = do it like i show
image2 = the clean button
image3 = after button was pressed

and here is the code:
Code: Pascal  [Select][+][-]
  1. procedure AssignIcon(const ABitBtn: TBitBtn; const AName: string);
  2. var
  3.   ico: TIcon;
  4. begin
  5.   ico := TIcon.Create;
  6.   try
  7.     ico.LoadFromResourceName(HINSTANCE, AName);
  8.     ABitBtn.Glyph.Assign(ico);
  9.   finally
  10.     ico.Free;
  11.   end;
  12. end;
  13.  
  14. procedure TForm1.BitBtn1Click(Sender: TObject);
  15. begin
  16.   if Sender is TBitBtn then
  17.     AssignIcon((Sender as TBitBtn), 'HEART');
  18. end;

Enjoy!
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

wp

  • Hero Member
  • *****
  • Posts: 13207
Re: How can I display the built-in icons on the buttons?
« Reply #2 on: January 28, 2024, 12:14:15 pm »
The resources shown in your screenshot seem to be the default resource files which the LCL is linking in. These resources are use by TBitBtn and TSpeedButton as default icons. Simply set the Kind property, and the icon corresponding to the Kind value, will appear.

iruanpan

  • New Member
  • *
  • Posts: 10
Re: How can I display the built-in icons on the buttons?
« Reply #3 on: January 28, 2024, 12:27:47 pm »
You need to place Icons in the RT_ICON section and call my method
image1 = do it like i show
image2 = the clean button
image3 = after button was pressed

and here is the code:
Code: Pascal  [Select][+][-]
  1. procedure AssignIcon(const ABitBtn: TBitBtn; const AName: string);
  2. var
  3.   ico: TIcon;
  4. begin
  5.   ico := TIcon.Create;
  6.   try
  7.     ico.LoadFromResourceName(HINSTANCE, AName);
  8.     ABitBtn.Glyph.Assign(ico);
  9.   finally
  10.     ico.Free;
  11.   end;
  12. end;
  13.  
  14. procedure TForm1.BitBtn1Click(Sender: TObject);
  15. begin
  16.   if Sender is TBitBtn then
  17.     AssignIcon((Sender as TBitBtn), 'HEART');
  18. end;

Enjoy!

Thank you very much for your help

iruanpan

  • New Member
  • *
  • Posts: 10
Re: How can I display the built-in icons on the buttons?
« Reply #4 on: January 28, 2024, 12:28:43 pm »
The resources shown in your screenshot seem to be the default resource files which the LCL is linking in. These resources are use by TBitBtn and TSpeedButton as default icons. Simply set the Kind property, and the icon corresponding to the Kind value, will appear.

That's what I want. Thank you very much for your help!

 

TinyPortal © 2005-2018