Change btn icon lazarus / 31-LCL ---------------------------------------------------------------------- Pe3s · 2021-10-27 19:14 Hello, how can I change imageindex.  play -pause - and back play ---------------------------------------------------------------------- speter · 2021-10-27 22:03 G'Day Pe3s, I think you need to include some more information, if you really want any help. Is "imageindex" a local variable you have created? Or is it some object's property or method? Also, I might be helpful to specify what version of Lazarus / FPC you are using and what OS (& version) you are using. cheers S. ---------------------------------------------------------------------- Pe3s · 2021-10-28 05:38 My point is that when you click on the button, the icon changes, when you click again, the icon returns ---------------------------------------------------------------------- Pe3s · 2021-10-28 05:52 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i varim: Boolean;beginif im thenbtn.ImageIngex :=1elsebtn.ImageIndex := 2;end ---------------------------------------------------------------------- howardpc · 2021-10-28 08:14 Drop a bitbtn and an imagelist on the main form of a new project. Populate the imagelist as desired, and connect it to the button's Images property in the Object Inspector. Complete the button's OnClick and form's OnCreate as follows: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit uMain; {$mode objfpc}{$H+} interface uses  Forms, Controls, Buttons; type  TForm1 = class(TForm)    BitBtn: TBitBtn;    ImageList: TImageList;    procedure BitBtnClick(Sender: TObject);    procedure FormCreate(Sender: TObject);  private    alternativeImage: Boolean;  end; var  Form1: TForm1; implementation procedure TForm1.BitBtnClick(Sender: TObject);var  btn: TBitBtn absolute Sender;begin  if (ImageList.Count < 2) or not Sender.InheritsFrom(TBitBtn) then    Exit;  case alternativeImage of  True:  btn.ImageIndex := 0;    False: btn.ImageIndex := 1;  end;  alternativeImage := not alternativeImage;end; procedure TForm1.FormCreate(Sender: TObject);begin  BitBtnClick(BitBtn);end; {$R *.lfm} end. ---------------------------------------------------------------------- Pe3s · 2021-10-28 16:09 @ howardpc Thank You ---------------------------------------------------------------------- Pe3s · 2021-10-28 17:13 I am also interested in how you can still change the icons after clicking on the button using the TSpeedButton and ImageList components, something like the speaker icon and the crossed out speaker ---------------------------------------------------------------------- howardpc · 2021-10-28 18:43 Quote from: Pe3s on October 28, 2021, 07:38:00 amMy point is that when you click on the button, the icon changes, when you click again, the icon returns Quote from: Pe3s on October 28, 2021, 07:13:31 pmI am also interested in how you can still change the icons after clicking on the button using the TSpeedButton and ImageList components, something like the speaker icon and the crossed out speaker I don't see what difference there is between these two scenarios. ---------------------------------------------------------------------- Pe3s · 2021-10-28 19:34 If I want to run the procedure BitBtnClick (BitBtn); e.g. from another button it will not cause the program to malfunction? ---------------------------------------------------------------------- howardpc · 2021-10-28 20:37 An advantage of a RAD environment like Lazarus is that you can try things out usually very quickly to see what happens. Drop a standard button on the project I suggested earlier. Name it SecondaryButton. Double-click the button to generate an OnClick handler for it, and complete the skeleton code Lazarus writes for you: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.SecondaryButtonClick(Sender: TObject);begin  BitBtnClick(BitBtn);end;Try it, and see how it behaves. ---------------------------------------------------------------------- Pe3s · 2021-10-29 16:25 Thank you for solving the problem. Regards