1 (edited by m.alin 2023-03-13 12:58:28)

Topic: BackColor of a button which is pressed

Hi all,

I would need your help to solve an issue I'm having.
I would like to show the user which button is pressed, by changing it's backcolor.

I tried another approach, like putting a panel under the button and if the 3rd button is pressed, the panel will move under the third button. All good until I've checked the scaled option on the main form, then this panel is not moving into the right position.

What would be the best solution to have this done?

Thank you.

Alin

Post's attachments

Attachment icon scaled.png 5.12 kb, 32 downloads since 2023-03-13 

Best regards,
Alin

Re: BackColor of a button which is pressed

var BP:TToolbar;
    SP:TSpeedButton;
    i:integer;
begin
BP := TToolbar.Create(Form1);
BP.Parent := Form1;
for i:=0 to 3 do
    begin
      SP:=TSpeedButton.Create(BP);
      SP.Caption:='...';
      SP.Parent:=BP;
      SP.GroupIndex:=1;
    end;
end.

https://i.imgur.com/mJhVGJI.png

Re: BackColor of a button which is pressed

Hi M.Alin,
Your idea of using a panel is fine but to avoid issues with the panel not being aligned with the associated button when the form is resized, why don't you place the button INSIDE the panel - that way, they should always resize together as the button is subordinate to its panel (see 'which button 1' in the attachment).
For a 'zero code' option, if you use 'visual styles' then many of the styles automatically highlight the button that has been clicked (see 'which button 2' in the attachment) so there is no need for any panels at all.
Another option without using panels would be to do something like change the selected button's font size or put the caption in upper case).
Derek.

Post's attachments

Attachment icon which button.zip 771.07 kb, 149 downloads since 2023-03-13 

Re: BackColor of a button which is pressed

Hi all,

Thank you very much for your responses.
Awesome workarounds:)
Thank you once again for sharing your ideas.

Best regards,
Alin

Best regards,
Alin