2812:Control Font Styles

2812:Control Font Styles

KEYWORDS: Font Style AREA: VCL Programming

Control Font Styles:

This code will change the font style of a Edit
when selected. This code could be implemented to
control font style on other objects.

With a Edit(Edit1) and a ListBox(ListBox1) on a form
Add the following Items to the ListBox:
   fsBold
   fsItalic
   fsUnderLine
   fsStrikeOut

procedure TForm1.ListBox1Click(Sender: TObject);
var
  X : Integer;
type
  TLookUpRec = record
    Name: String;
    Data: TFontStyle;
  end;
const
  LookUpTable: array[1..4] of TLookUpRec =
  ((Name: 'fsBold'; Data: fsBold),
   (Name: 'fsItalic'; Data: fsItalic),
   (Name: 'fsUnderline'; Data: fsUnderline),
   (Name: 'fsStrikeOut'; Data: fsStrikeOut));
begin
  X := ListBox1.ItemIndex;
  Edit1.Text := ListBox1.Items[X];
  Edit1.Font.Style := [LookUpTable[ListBox1.ItemIndex+1].Data];
end;

        TI

DISCLAIMER: You have the right to use this technical information subject to the terms of the No-Nonsense License Statement that you received with the Borland product to which this information pertains.


Return to Complete TI List