Recent

Author Topic: Change font style on button at runtime?  (Read 4412 times)

segfault

  • Full Member
  • ***
  • Posts: 107
Change font style on button at runtime?
« on: August 30, 2018, 02:39:42 pm »
I have several buttons with captions in regular font, but when a button is clicked I want to change the font style to bold. How do I do this?

Button1.Font.Style := ???

Thanks in advance.

Handoko

  • Hero Member
  • *****
  • Posts: 4327
  • My goal: build my own game engine using Lazarus
Re: Change font style on button at runtime?
« Reply #1 on: August 30, 2018, 02:42:55 pm »
Try something like this:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   Button1.Font.Style := [fsBold, fsItalic, fsUnderline, fsStrikeOut];
  4. end;

For you information, the Underline and StrikeOut styles didn't work on my test on Linux Gtk2.
« Last Edit: August 30, 2018, 02:45:29 pm by Handoko »

segfault

  • Full Member
  • ***
  • Posts: 107
Re: Change font style on button at runtime?
« Reply #2 on: August 30, 2018, 03:20:06 pm »
Thanks Handoko,

At the same time I need to turn off bold on the other buttons, but I figured out how to do that :

Code: Pascal  [Select][+][-]
  1.  procedure TForm1.Button1Click(Sender: TObject);
  2.  begin
  3.    Button1.Font.Style := [fsBold];
  4.    // turn off bold in other buttons
  5.    Button2.Font.Style := Button2.Font.Style - [fsBold];
  6.  end;

 

TinyPortal © 2005-2018