Author: Jorge Abel Ayala Marentes
You can display the available fonts in a WYSIWYG fashion.
Answer:
Start a new project, add a TListBox, in the Form´s OnCreate event code:
1 2 procedure TForm1.FormCreate(Sender: TObject);
3 begin4 ListBox1.Items := Screen.Fonts;
5 end;
Set the ListBox´s style property to lbOwnerDrawVariable and finally and the
following code to the ListBox´s OnDrawItem and OnMeasureItem events
6 7 procedure TForm1.ListBox1MeasureItem(Control: TWinControl; Index: Integer;
8 var Height: Integer);
9 var10 h: integer;
11 begin12 with Control as TListBox do13 begin14 Canvas.Font.Name := Items[Index];
15 h := Canvas.TextHeight(Items[Index]);
16 end;
17 Height := h;
18 end;
19 20 procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
21 Rect: TRect; State: TOwnerDrawState);
22 begin23 with Control as TListBox do24 begin25 Canvas.Font.Name := Items[Index];
26 Canvas.FillRect(Rect);
27 Canvas.TextOut(Rect.Left, Rect.Top, Items[Index]);
28 end;
29 end;