Recent

Author Topic: Label color  (Read 1763 times)

bobbylong

  • Newbie
  • Posts: 2
Label color
« on: January 21, 2021, 02:57:47 pm »
When using Jujibo to make a TJButton I would like the color of the font on the button to change when clicked.
Is this possible? I have only had Lazarus for 3 days and Jujibo 1 day so please excuse my newness.

Christian Becker

  • New member
  • *
  • Posts: 9
Re: Label color
« Reply #1 on: January 24, 2021, 09:02:59 pm »
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   Button1.Font.Color := [color];
  4. end;              

This will change the font color to [color], which can either be a predifined one like ClButtonTxt or an RGB value like $000000 for black.
I assume you know what RGB colours are and that you know how they're represented in hexadecimal notation.
If not, have a look here: https://www.w3schools.com/colors/colors_picker.asp, only instead of # Lazarus uses $.

This will change the colour of the font on the button permanently. Not sure if this is what you're after... I think you probably want it to revert back once you release the mouse button. Not sure if and how that works.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Label color
« Reply #2 on: January 24, 2021, 10:26:47 pm »
I think you probably want it to revert back once you release the mouse button. Not sure if and how that works.

Instead of responding to OnClick, do it for OnMouseDown and OnMouseUp:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1MouseDown(Sender: TObject; Button: TMouseButton;
  2.   Shift: TShiftState; X, Y: Integer);
  3. begin
  4.   Button1.Font.Color := clYellow;
  5. end;
  6.  
  7. procedure TForm1.Button1MouseUp(Sender: TObject; Button: TMouseButton;
  8.   Shift: TShiftState; X, Y: Integer);
  9. begin
  10.   Button1.Font.Color := clBtnText;
  11. end;

Note that this code is for a standard TButton; I don't know whether it'll be valid for a TJButton :-[
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

bobbylong

  • Newbie
  • Posts: 2
Re: Label color
« Reply #3 on: January 24, 2021, 10:39:40 pm »
It didn't seem to work, maybe because what I actually need to change is the TJlabel, not actually the button. I'll keep digging.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Label color
« Reply #4 on: January 25, 2021, 01:02:05 am »
I know nothing about the jujibo controls but if they are descended from (or similar to) the standard controls, there should be no problem; only, instead of the button's, change the label's Font.Color.

Note that all this are just rather wild guesses both because my lack of knowledge and because you didn't show any of your code or the form's arrangement. Also, you titled the topic about a label, then talked about a button and now we're back to the label; it's almost impossible to even guess meaningfully about what you might really need ...
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

jujibo

  • Full Member
  • ***
  • Posts: 114
Re: Label color
« Reply #5 on: February 03, 2021, 05:55:46 pm »
When using Jujibo to make a TJButton I would like the color of the font on the button to change when clicked.
Is this possible? I have only had Lazarus for 3 days and Jujibo 1 day so please excuse my newness.

Hi. You can change font color in this way:

Code: Pascal  [Select][+][-]
  1. JButton1.LCaption.Font.Color:= clRed;

 

TinyPortal © 2005-2018