Recent

Author Topic: Color Buttons  (Read 3612 times)

Weitentaaal

  • Hero Member
  • *****
  • Posts: 553
Color Buttons
« on: January 13, 2025, 03:37:51 pm »
Hello,

i wanted to change Color of a Button. Currently using BGRA Buttons (TBCButton / TColorSpeedbutton). But whenever the Button gets Disabled i cant see a change at the Button. Is it Possible to recreate the windows 10 Button but beeing able to change Color ?. Speedbutton does Change the Background color when Disabled but not the Font Color. Are there any other Buttons i could use ? Previous had CustomDrawn Control "TCDButton" but the Buttons kept Focus all the time without beeing able to remove Focus. I would love to use BGRA Buttons.

Thanks in advance for any help

lainz

  • Hero Member
  • *****
  • Posts: 4686
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Color Buttons
« Reply #1 on: January 13, 2025, 04:20:28 pm »
Hi. Create your own button is not that hard... Check tbcxbutton
https://wiki.freepascal.org/BGRAControls#TBCXButton

Code: Pascal  [Select][+][-]
  1. procedure TForm1.BCXButton1RenderControl(Sender: TObject; Bitmap: TBGRABitmap;
  2.   State: TBCGraphicButtonState);
  3. begin
  4.   Bitmap.FillTransparent;
  5.   case State of
  6.     gbsNormal: begin
  7.       Bitmap.Fill(BGRA(100,0,0,255));
  8.       Bitmap.TextRect(Rect(0,0,Bitmap.Width,Bitmap.Height),
  9.       TBCXButton(Sender).Caption, taCenter, tlCenter, BGRAWhite);
  10.     end;
  11.     gbsHover: begin
  12.       Bitmap.Fill(BGRA(200,0,0,255));
  13.       Bitmap.TextRect(Rect(0,0,Bitmap.Width,Bitmap.Height),
  14.       TBCXButton(Sender).Caption, taCenter, tlCenter, BGRAWhite);
  15.     end;
  16.     gbsActive: begin
  17.       Bitmap.Fill(BGRA(50,0,0,255));
  18.       Bitmap.TextRect(Rect(0,0,Bitmap.Width,Bitmap.Height),
  19.       TBCXButton(Sender).Caption, taCenter, tlCenter, BGRAWhite);
  20.     end;
  21.     gbsDisabled: begin
  22.       Bitmap.Fill(BGRA(100,100,100,255));
  23.       Bitmap.TextRect(Rect(0,0,Bitmap.Width,Bitmap.Height),
  24.       TBCXButton(Sender).Caption, taCenter, tlCenter, BGRABlack);
  25.     end;
  26.   end;
  27. end;
« Last Edit: January 13, 2025, 05:03:17 pm by lainz »

jamie

  • Hero Member
  • *****
  • Posts: 6801
Re: Color Buttons
« Reply #2 on: January 13, 2025, 07:10:07 pm »
I think it's time to make tcolorbutton and make it part of the stock controls using the custom control class
 This is getting asked to many times .
The only true wisdom is knowing you know nothing

dsiders

  • Hero Member
  • *****
  • Posts: 1345
Re: Color Buttons
« Reply #3 on: January 13, 2025, 08:10:19 pm »
I think it's time to make tcolorbutton and make it part of the stock controls using the custom control class
 This is getting asked to many times .

And I think it's time for people to use the Forum Search feature. Or stop designing ugly user interfaces.
Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

lainz

  • Hero Member
  • *****
  • Posts: 4686
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Color Buttons
« Reply #4 on: January 13, 2025, 09:14:49 pm »
I think it's time to make tcolorbutton and make it part of the stock controls using the custom control class
 This is getting asked to many times .

That will be a solution.  :)

Weitentaaal

  • Hero Member
  • *****
  • Posts: 553
Re: Color Buttons
« Reply #5 on: January 14, 2025, 07:13:32 am »
Hey sorry if i did ask this question again. i did search the forum which led me to this topic: "https://forum.lazarus.freepascal.org/index.php?topic=36774.0" . However i did not know how easy it is to create my own Button. BGRA controls does provide a lot of options already. Thanks Lanz i will try to go with your suggestion.

Weitentaaal

  • Hero Member
  • *****
  • Posts: 553
Re: Color Buttons
« Reply #6 on: January 14, 2025, 07:33:04 am »
Do i need to create a Package if i want to inherit the BCXButton and create my own component ?. would be much more convenient if i could have a visual component for the inherited Button.
« Last Edit: January 14, 2025, 08:12:09 am by Weitentaaal »

lainz

  • Hero Member
  • *****
  • Posts: 4686
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Color Buttons
« Reply #7 on: January 14, 2025, 01:04:56 pm »
Do i need to create a Package if i want to inherit the BCXButton and create my own component ?. would be much more convenient if i could have a visual component for the inherited Button.

Yes you need to create a package and a descendant from TBCXButton.

 

TinyPortal © 2005-2018