1

My problem is like below, so I want all the checkboxes Bold,Italic and Underline to work out if I checked all of them.

I try searching similar problem from this site to help me but their question just to confusing..

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  if Checkbox1.Checked = True then
  Label1.Font.Style := [fsBold] else
  Label1.Font.Style := [];
end;

procedure TForm1.CheckBox2Click(Sender: TObject);
begin
  if Checkbox2.Checked = True then
  Label1.Font.Style := [fsItalic] else
  Label1.Font.Style := [];
end;

procedure TForm1.CheckBox3Click(Sender: TObject);
begin
  if Checkbox3.Checked = True then
  Label1.Font.Style := [fsUnderline] else
  Label1.Font.Style := [];
end;

end;
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
Razgris6146
  • 41
  • 1
  • 3

1 Answers1

12

The font style is a set of different TFontStyles, so for each checkbox you need to add the respective style to the set, if it is checked or remove it, if it is unchecked, e.g.

if Checkbox1.Checked then
  Label1.Font.Style := Label1.Font.Style + [fsBold]; 
else
  Label1.Font.Style := Label1.Font.Style - [fsBold] 

PS: You should always use Boolean values directly and not compare them to True/False

Sebastian Proske
  • 8,255
  • 2
  • 28
  • 37
  • got it. In another question I had explain little bit more about Enumerable type. Maybe is something useful. https://stackoverflow.com/questions/43943107/how-to-hide-multiple-tabs-in-ttabcontrol/43946736#43946736 – Ricardo da Rocha Vitor May 22 '17 at 13:50