home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1996 August / VPR9608A.BIN / del20try / install / data.z / FONTLIST.PAS < prev    next >
Pascal/Delphi Source File  |  1996-05-08  |  2KB  |  65 lines

  1. unit Fontlist;
  2.  
  3. interface
  4.  
  5. uses Windows, Classes, Graphics, Forms, Controls, StdCtrls;
  6.  
  7. type
  8.   TForm1 = class(TForm)
  9.     ListBox1: TListBox;
  10.     Label1: TLabel;
  11.     FontLabel: TLabel;
  12.     procedure FormCreate(Sender: TObject);
  13.     procedure ListBox1Click(Sender: TObject);
  14.     procedure DrawItem(Control: TWinControl; Index: Integer; Rect: TRect;
  15.       State: TOwnerDrawState);
  16.     procedure ListBox1MeasureItem(Control: TWinControl; Index: Integer;
  17.       var Height: Integer);
  18.   private
  19.     { Private declarations }
  20.   public
  21.     { Public declarations }
  22.   end;
  23.  
  24. var
  25.   Form1: TForm1;
  26.  
  27. implementation
  28.  
  29. {$R *.DFM}
  30.  
  31. procedure TForm1.FormCreate(Sender: TObject);
  32. begin
  33.   Listbox1.Items := Screen.Fonts;
  34. end;
  35.  
  36. procedure TForm1.ListBox1Click(Sender: TObject);
  37. begin
  38.   FontLabel.Caption := ListBox1.Items[ListBox1.ItemIndex];
  39. end;
  40.  
  41. procedure TForm1.DrawItem(Control: TWinControl; Index: Integer;
  42.   Rect: TRect; State: TOwnerDrawState);
  43. begin
  44.   with ListBox1.Canvas do
  45.   begin
  46.     FillRect(Rect);
  47.     Font.Name := ListBox1.Items[Index];
  48.     Font.Size := 0;    // use font's preferred size
  49.     TextOut(Rect.Left+1, Rect.Top+1, ListBox1.Items[Index]);
  50.   end;
  51. end;
  52.  
  53. procedure TForm1.ListBox1MeasureItem(Control: TWinControl; Index: Integer;
  54.   var Height: Integer);
  55. begin
  56.   with ListBox1.Canvas do
  57.   begin
  58.     Font.Name := Listbox1.Items[Index];
  59.     Font.Size := 0;                 // use font's preferred size
  60.     Height := TextHeight('Wg') + 2; // measure ascenders and descenders
  61.   end;
  62. end;
  63.  
  64. end.
  65.