Recent

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

frederic

  • Full Member
  • ***
  • Posts: 226
how to change color of a button
« on: May 04, 2017, 04:51:40 pm »
dear specialists

simple question...
following didn't work
Code: Pascal  [Select][+][-]
  1. { TForm1 }
  2.  
  3. procedure TForm1.Button1Click(Sender: TObject);
  4. begin
  5.   button2.color:=clred;
  6.   button1.color:=cldefault;
  7. end;
  8.  
  9. procedure TForm1.Button2Click(Sender: TObject);
  10. begin
  11.    button1.color:=clblue;
  12.     button2.color:=cldefault;
  13. end;                      

what is wrong with this

frederic

J-G

  • Hero Member
  • *****
  • Posts: 953
Re: how to change color of a button
« Reply #1 on: May 04, 2017, 05:03:55 pm »
Most annoying but the colour of a TButton is inherited and can't be changed - even though the object inspector makes it look as though it is a simple matter.

I resolved this by installing Jujibo components and then using TJButton which does have a modifyable colour attribute.

FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

balazsszekely

  • Guest
Re: how to change color of a button
« Reply #2 on: May 04, 2017, 05:06:04 pm »
Hi Frederic,

TButton is just a wrapper around the standard OS button, therefor the color cannot be changed. Use a custom component instead.

Bart

  • Hero Member
  • *****
  • Posts: 5235
    • Bart en Mariska's Webstek
Re: how to change color of a button
« Reply #3 on: May 04, 2017, 07:13:07 pm »
Or disable themes.

Bart

frederic

  • Full Member
  • ***
  • Posts: 226
Re: how to change color of a button
« Reply #4 on: May 04, 2017, 08:46:32 pm »
thanks
 for the reactions,
i know what to do... when i have some time left

frederic

valdir.marcos

  • Hero Member
  • *****
  • Posts: 1106
Re: how to change color of a button
« Reply #5 on: May 05, 2017, 10:11:12 am »
Or disable themes.

How?
I have disable Windows Theme on Project Options of Lazarus IDE, but it does not seem to be enough.
Please, see image.

Thaddy

  • Hero Member
  • *****
  • Posts: 13987
  • Probably until I exterminate Putin.
Re: how to change color of a button
« Reply #6 on: May 05, 2017, 10:14:05 am »
Or disable themes.

Bart
That doesn't work either: TButton under windows can't have color working. Period.
Specialize a type, not a var.

balazsszekely

  • Guest
Re: how to change color of a button
« Reply #7 on: May 05, 2017, 11:13:08 am »
Quote
That doesn't work either: TButton under windows can't have color working. Period.
Actually you can by setting the button's window style to BS_OWNERDRAW and handling WM_DRAWITEM message. The point is the owner draw button is no longer a standard looking windows button, so it make no sense to change the color if you ask me, but this is just a personal opinion. 

Thaddy

  • Hero Member
  • *****
  • Posts: 13987
  • Probably until I exterminate Putin.
Re: how to change color of a button
« Reply #8 on: May 05, 2017, 11:30:08 am »
In theory that should be possible, but I for one never succeeded in the case of TButton. Only with TSpeedButton and partially TBitBtn.
I also never saw a *working* example anywhere else...in any language, not just Pascal.
« Last Edit: May 05, 2017, 11:32:31 am by Thaddy »
Specialize a type, not a var.

balazsszekely

  • Guest
Re: how to change color of a button
« Reply #9 on: May 05, 2017, 11:33:44 am »

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: how to change color of a button
« Reply #10 on: April 24, 2019, 09:43:08 pm »
I know this thread is old, but I understand the frustration of Buttons in pascal not having the ability to change the color.

In .NET, not only could you make a normal button flat, you could change it's back color and hover color.

I made an app using that button with hover and back color. Used it like a marker to show the user what text memo they were reading.
It's more of a cosmetic thing.

Almost the same customization as a web button, but without CSS.

However, nonetheless, its very frustrating try to use some controls is LAZ/pascal... they are very limited.

Now, that I am trying to convert the >NET app to LAZ.... I have to do away with the flat Hover/color button customization.

The one thing I miss about .NET,  great controls and easy to customize.
But, Visual Studio is out for me because of install issues. Have to get e new PC. Ain't happening for awhile.

Just my 2 cents :D


Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: how to change color of a button
« Reply #11 on: April 24, 2019, 11:37:08 pm »
Well.. someone in another thread let me know of a control I can use that handles colors.
It even has a hover color.

It's BGRAControls
« Last Edit: April 24, 2019, 11:42:00 pm by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

Sino7524

  • Newbie
  • Posts: 1
Re: how to change color of a button
« Reply #12 on: November 29, 2023, 06:10:49 pm »
I usually use a TSpeedButton as a button because it allows you to add a Glyph (an image on the button). Go to the "Transparent" property of the TSpeedButton and change it to False. Next, change the "Flat" property to True and now it will allow you to change the color. you can also use these lines of code:

Button.Flat := True;
Button.Transparent := False;

1HuntnMan

  • Full Member
  • ***
  • Posts: 150
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: how to change color of a button
« Reply #13 on: November 29, 2023, 08:56:38 pm »
I think awhile back that you could change the color of the SpdBtn at least to clBtnFace. It's been awhile but when I add a TSpeedbutton to a form, it's white and you can't change it. Maybe it was before I bought my new computer with Winders 11, ugh! My old computer had Winders 10 Pro. When I add a TBitBtn or a TSpeedButton, they are both white.

1HuntnMan

  • Full Member
  • ***
  • Posts: 150
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: how to change color of a button
« Reply #14 on: November 29, 2023, 08:58:04 pm »
Good question, why does the button component have a color property if you can't change it?

 

TinyPortal © 2005-2018