1 (edited by scribtx 2020-11-17 15:17:33)

Topic: Menu Button with icon and writing

Hi MVD family!

Hope all of you and yours are well and safe. I have a favor to ask of the community, how does one create a button on Form1 that will have an icon and text?
Thanks,

scribtx

Post's attachments

Attachment icon Screenshot_1.png 5.32 kb, 98 downloads since 2020-11-17 

Re: Menu Button with icon and writing

Hello scribtx

you can do it in two steps

1 - Create your image(s) for button with a drawing program with which you add your text under the image.
2 - You enter this snippet (adapted to your needs) either between BEGIN and END. at the end of script or into a form with OnShow event

var     ImageList: TImageList;


begin
                                                                          // On créée une nouvelle ImageList
  ImageList:=TImageList.Create(Form1);
  ImageList.Masked:=false;
  ImageList.ColorDepth:=cd32bit;             
  ImageList.Width := 16;                                        // Taille des images
  ImageList.Height := 16;

                                                                          // Chargement des 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

                                                                     // Chargement de  ImageList pour les boutons
  Form1.Button1.Images := ImageList;
  Form1.Button2.Images := ImageList;
  Form1.Button3.Images := ImageList;
  Form1.Button4.Images := ImageList;
  Form1.Button5.Images := ImageList;
  Form1.Button6.Images := ImageList;

                                                                      // Sélection des images pour les boutons
  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.


As format you can use PNG, JPG, BMP (very heavy)

JB

Re: Menu Button with icon and writing

Jen--

Excellent! Thank you my friend!