Recent

Author Topic: Change button background color  (Read 1927 times)

dodgebros

  • Full Member
  • ***
  • Posts: 165
Change button background color
« on: June 12, 2024, 06:23:35 am »
Can you guys direct me to a button that i can change the background color to?  I am using MS Windows.

Thanks,
TD

Khrys

  • New Member
  • *
  • Posts: 38
Re: Change button background color
« Reply #1 on: June 12, 2024, 07:11:19 am »
Win32 for some reason doesn't allow changing the background color of native buttons; so whatever implementation is used will have to be owner-drawn.

One of the most used libraries in the Lazarus ecosystem is  bgracontrols, among whose (owner-drawn) controls is  TColorSpeedButton, which does exactly what you want. Confusingly in the LCL there's  TSpeedButton, which allows displaying a bitmap alongside the caption (but doesn't support changing the background color) and  TColorButton  which is an extended version of the former that's meant to be used in conjunction with a color picker (it simply displays a color as a filled rectangle on the button, but still doesn't allow changing its background color).

cdbc

  • Hero Member
  • *****
  • Posts: 1344
    • http://www.cdbc.dk
Re: Change button background color
« Reply #2 on: June 12, 2024, 07:58:22 am »
Hi
Use a 'TPanel' instead of a button...
The "push-button" effect you can simulate with drawing the bevels yourself.
The same goes for more modern effects, e.g.: make it look like a hyperlink etc.
Let me know, if you need it, I might dig out some examples...
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

Eugene Loza

  • Hero Member
  • *****
  • Posts: 711
    • My games in Pascal
Re: Change button background color
« Reply #3 on: June 12, 2024, 08:24:53 am »
Another solution that was working for me in the past - switch to a different widgetset, e.g. qt5. But couldn't get any of the widgetsets other than default one to work in my quick test this morning, either the process became more convoluted or it's because FpcUpDeluxe installation doesn't automatically pull the corresponding required files though I don't see any obvious options to install those.
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

dodgebros

  • Full Member
  • ***
  • Posts: 165
Re: Change button background color
« Reply #4 on: June 12, 2024, 06:11:15 pm »
cdbc how did you impliment thid?

Code: Text  [Select][+][-]
  1. The same goes for more modern effects, e.g.: make it look like a hyperlink etc.

TD

cdbc

  • Hero Member
  • *****
  • Posts: 1344
    • http://www.cdbc.dk
Re: Change button background color
« Reply #5 on: June 12, 2024, 07:15:04 pm »
Hi
I'll share with you the main view/form of the app in the photo below.
You should be able to load it into lazarus, but may have comment out some code regarding plugins and mvvm-stuff, but hey, the panel-stuff is all there.
Have fun  8-)
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

dodgebros

  • Full Member
  • ***
  • Posts: 165
Re: Change button background color
« Reply #6 on: June 12, 2024, 07:29:09 pm »
thank you cdbc
TD

Hansvb

  • Hero Member
  • *****
  • Posts: 638
Re: Change button background color
« Reply #7 on: June 21, 2024, 02:06:53 pm »
hi cdbc,

i took a peek at the example and in the Form KeyDown I see codes that represent a key ($53).
Is there a list of these somewhere?


Eugene Loza

  • Hero Member
  • *****
  • Posts: 711
    • My games in Pascal
Re: Change button background color
« Reply #9 on: June 21, 2024, 02:26:46 pm »
Quote
Is there a list of these somewhere?
Yes, unfortunately I don't see it in any convenient form (most likely just can't find), so looking at LCLType unit seems the most convenient for me: https://gitlab.com/freepascal.org/lazarus/lazarus/-/blob/main/lcl/lcltype.pp?ref_type=heads#L397
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

cdbc

  • Hero Member
  • *****
  • Posts: 1344
    • http://www.cdbc.dk
Re: Change button background color
« Reply #10 on: June 21, 2024, 03:07:01 pm »
Hi
Bobby100 is right, these are just the ascii-ordinals expressed as hex:
$20 = ' ' ~ dec. 32
$30 = '0' ~ dec. 48
$40 = '@' ~ dec. 64
$41 = 'A' ~ dec. 65
etc...
It's just easier for me in some situations, but Eugene Loza is also right, use LCLType, for convenience  :D
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

Hansvb

  • Hero Member
  • *****
  • Posts: 638
Re: Change button background color
« Reply #11 on: June 21, 2024, 03:20:51 pm »

lainz

  • Hero Member
  • *****
  • Posts: 4572
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Change button background color
« Reply #12 on: June 21, 2024, 03:45:22 pm »
Use BGRAControls, we have a lot of buttons to choose from.

cdbc

  • Hero Member
  • *****
  • Posts: 1344
    • http://www.cdbc.dk
Re: Change button background color
« Reply #13 on: June 21, 2024, 04:09:32 pm »
Hi
Yes, but they introduce a dependency on BGRAxxx etc... Huge code-base.
The example form was made with /only/ controls found in standard LCL.
With just a few small tricks added...
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

lainz

  • Hero Member
  • *****
  • Posts: 4572
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Change button background color
« Reply #14 on: June 21, 2024, 05:55:16 pm »
Yes but you won't have a good looking button anyways. BGRA is well tested and have a lot of possibilities: material design button with animations, button with gradients, static buttons, image buttons, svg buttons, and not only buttons if you want to style more controls.

Quality comes with a price! A few mb added to your final exe, with nowadays internet speed is nothing to worry...
« Last Edit: June 21, 2024, 05:59:17 pm by lainz »

 

TinyPortal © 2005-2018