Topic: [Script] Own icons for buttons

Own icons for buttons


var
    ImageList: TImageList;


begin
  // create new ImageList
  ImageList:=TImageList.Create(Form1);
  ImageList.Masked:=false;
  ImageList.ColorDepth:=cd32bit;
  // size of images                 
  ImageList.Width := 16;
  ImageList.Height := 16;

  // load images
  ImageList.AddPng(ExtractFilePath(Application.ExeName)+'Icons\key.png');      // 0 - index if image
  ImageList.AddPng(ExtractFilePath(Application.ExeName)+'Icons\accept.png');   // 1
  ImageList.AddPng(ExtractFilePath(Application.ExeName)+'Icons\link.png');     // 2
  ImageList.AddPng(ExtractFilePath(Application.ExeName)+'Icons\window.png');   // 3

  // Change ImageList for buttons
  Form1.Button1.Images := ImageList;
  Form1.Button2.Images := ImageList;
  Form1.Button3.Images := ImageList;
  Form1.Button4.Images := ImageList;
  Form1.Button5.Images := ImageList;
  Form1.Button6.Images := ImageList;

  // Select images for buttons
  Form1.Button1.ImageIndex := 0;
  Form1.Button2.ImageIndex := 1;
  Form1.Button3.ImageIndex := 2;
  Form1.Button4.ImageIndex := 3;
  Form1.Button5.ImageIndex := 3;
  Form1.Button6.ImageIndex := 3;
end.

Project example:

Post's attachments

Attachment icon Own icons for buttons.zip 6.67 kb, 1079 downloads since 2017-06-23 

Dmitry.

Re: [Script] Own icons for buttons

Hey Dmitry ,


TImageList !! You did it !!  That's great !!


Unfortunately, I get an "UnknownType" error with 3.4 stable and with the 3.4 beta (found on this post http://myvisualdatabase.com/forum/viewt … p?id=3352) that seemed to be the latest beta version...


Is there a newer beta I missed somewhere ?


Cheers


Math

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: [Script] Own icons for buttons

Please download latest beta version 3.5
https://www.dropbox.com/s/f3j4kfpnttm1o … b.zip?dl=0

Dmitry.

4 (edited by mathmathou 2017-06-24 00:40:03)

Re: [Script] Own icons for buttons

Hello again Dmitry,


Works perfectly with beta 3.5, thanks a million times.


Subsidiary question : Is there a limit of icons you can add to a TImageList (Like after 8, you have to create a second list) ?



ADDITIONAL HELP FOR PEOPLE WHO WANT TO USE CUSTOM IMAGELIST


Until now, we could only add icons to Menus and PopupMenus with format Bitmap with transparency which were... well... ugly smile


With this new addition from Dmitry, you can now use PNG images with transparency for your Menus and PopupMenus very easily.


Here is an example on how to add a nice icon to a PopupMenu Item attached to a Tablegrid (of course, you'll have created you TImageList like shown in Dmitry's example)

procedure Form1_OnShow (Sender: string; Action: string);
var
    Pop : TPopupMenu;
    MyItem1 : TMenuItem;
begin
    Pop := TPopupMenu.Create(Form1);    //Create main PopupMenu
    Pop.Images := ImageList;            //Assign TImageList to PopupMenu

    MyItem1 := TMenuItem.Create(Pop);   //First Item of the PopupMenu
    MyItem1.Caption := 'Test pop Menu'; //Caption of the Item
    MyItem1.ImageIndex := 1;            //Image index assigned to the Item
    Pop.Items.Add(MyItem1);             //Add Item to PopupMenu

    Form1.TableGrid1.PopupMenu := Pop;  //Assign PopupMenu to Tablegrid
end;

Hope this helps


Cheers


Math

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: [Script] Own icons for buttons

mathmathou
I think there is no limit for icons.

Dmitry.

Re: [Script] Own icons for buttons

Great, next step would it be to be able to choose the application's icon? big_smile

Re: [Script] Own icons for buttons

Oh Happy ..... Grate Script Wait a long time

My Visual Database : I Love You
Easy For Beginner Student For Me

Re: [Script] Own icons for buttons

blackpearl8534 wrote:

can we use only one form with back or forward btns

Please explain your question in more details.

Dmitry.