Recent

Author Topic: how to change color of a button  (Read 25697 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 13936
  • Probably until I exterminate Putin.
Re: how to change color of a button
« Reply #15 on: November 29, 2023, 09:14:36 pm »
Good question, why does the button component have a color property if you can't change it?
It is simply a limitation of the underlying Windows API control. but yes, that property should be hidden on Windows. I already mentioned the alternatives..
Specialize a type, not a var.

Ten_Mile_Hike

  • New Member
  • *
  • Posts: 40
Re: how to change color of a button
« Reply #16 on: November 29, 2023, 09:37:04 pm »
Good question, why does the button component have a color property if you can't change it?

Because (IIRC) TButton can be assigned colors under Linux, but not windows

Handoko

  • Hero Member
  • *****
  • Posts: 5101
  • My goal: build my own game engine using Lazarus
Re: how to change color of a button
« Reply #17 on: November 30, 2023, 03:26:35 am »
Good question, why does the button component have a color property if you can't change it?

You can, if you're using Linux. As others already said, changing button color is OS depended behavior. You can know it from the "Restricted" tab in your Object Inspector.
« Last Edit: November 30, 2023, 04:08:43 am by Handoko »

Joanna

  • Hero Member
  • *****
  • Posts: 624
Re: how to change color of a button
« Reply #18 on: November 30, 2023, 04:28:17 pm »
Don’t use tbutton  ;D  Use tcdbutton in customdrawncontrols  8-)
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

DreamVB

  • Full Member
  • ***
  • Posts: 100
    • Memo Pad
Re: how to change color of a button
« Reply #19 on: December 01, 2023, 02:45:35 pm »
I use a one of the opensource Button components, or you could even use a panel and change its bevel state, or if you want to be creative create your own button.
Dream Believe Achieve

Joanna

  • Hero Member
  • *****
  • Posts: 624
Re: how to change color of a button
« Reply #20 on: December 08, 2023, 02:25:04 am »
A panel will not give the program user the feedback of having clicked something though... which is probably why buttons were invented.
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

KodeZwerg

  • Hero Member
  • *****
  • Posts: 1987
  • Fifty shades of code.
    • Delphi & FreePascal
Re: how to change color of a button
« Reply #21 on: December 08, 2023, 09:27:12 am »
A panel will not give the program user the feedback of having clicked something though... which is probably why buttons were invented.
Then you have missed playing with events I assume.
Exemplary:
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Panel1: TPanel;
  16.     procedure Panel1MouseEnter(Sender: TObject);
  17.     procedure Panel1MouseLeave(Sender: TObject);
  18.     procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton;
  19.       Shift: TShiftState; X, Y: Integer);
  20.     procedure Panel1MouseUp(Sender: TObject; Button: TMouseButton;
  21.       Shift: TShiftState; X, Y: Integer);
  22.   private
  23.  
  24.   public
  25.  
  26.   end;
  27.  
  28. var
  29.   Form1: TForm1;
  30.  
  31. implementation
  32.  
  33. {$R *.lfm}
  34.  
  35. { TForm1 }
  36.  
  37. procedure TForm1.Panel1MouseEnter(Sender: TObject);
  38. begin
  39.   Panel1.BorderStyle := bsSingle;
  40. end;
  41.  
  42. procedure TForm1.Panel1MouseLeave(Sender: TObject);
  43. begin
  44.   Panel1.BorderStyle := bsNone;
  45. end;
  46.  
  47. procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
  48.   Shift: TShiftState; X, Y: Integer);
  49. begin
  50.   Panel1.BevelOuter := bvLowered;
  51. end;
  52.  
  53. procedure TForm1.Panel1MouseUp(Sender: TObject; Button: TMouseButton;
  54.   Shift: TShiftState; X, Y: Integer);
  55. begin
  56.   Panel1.BevelOuter := bvRaised;
  57. end;
  58.  
  59. end.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

Joanna

  • Hero Member
  • *****
  • Posts: 624
Re: how to change color of a button
« Reply #22 on: December 09, 2023, 12:06:52 am »
Why go to such lengths to avoid using a real button though?
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

kwyan

  • New Member
  • *
  • Posts: 23
Re: how to change color of a button
« Reply #23 on: December 09, 2023, 04:03:05 am »
I use speed button, TSpeedButton. All you need to do is to set the button's property:

Flat is true
Transparent is false

Then you can set background colour and font colour as you like.

« Last Edit: December 09, 2023, 04:48:14 am by kwyan »

KodeZwerg

  • Hero Member
  • *****
  • Posts: 1987
  • Fifty shades of code.
    • Delphi & FreePascal
Re: how to change color of a button
« Reply #24 on: December 09, 2023, 09:58:40 am »
Why go to such lengths to avoid using a real button though?
Just because you said:
A panel will not give the program user the feedback of having clicked something though... which is probably why buttons were invented.
And I showed that you are wrong. At least in my humble opinion.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

lainz

  • Hero Member
  • *****
  • Posts: 4398
    • https://lainz.github.io/
Re: how to change color of a button
« Reply #25 on: December 09, 2023, 10:14:22 am »
Use BGRAControls, attached screenshots of TBCButton and TBCImageButton.

 

TinyPortal © 2005-2018