如何制作字体列表框(20分)

  • 主题发起人 主题发起人 1364581
  • 开始时间 开始时间
1

1364581

Unregistered / Unconfirmed
GUEST, unregistred user!
如何制作一个字体列表框,列表框中的下拉菜单字符如“宋体”、“黑体”、“行楷”等
字体名称是自己一个个输入的还是有什么控件可以自动装入,如果是一个个输入的,又怎
知道自己的计算机里有这些字体。
 
procedure TForm1.FormCreate(Sender: TObject);
begin
ComboBox1.Items := Screen.Fonts;
ComboBox1.ItemIndex := 0;
end;
 
接受答案了.
 
再给你一段,就是有点慢。
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
ComboBox1.Canvas.Font.Name := ComboBox1.Items[Index];
ComboBox1.Canvas.TextOut(Rect.Left + 2, Rect.Top, ComboBox1.Items[Index]);
end;

procedure TForm1.ComboBox1MeasureItem(Control: TWinControl; Index: Integer;
var Height: Integer);
var
tm: TEXTMETRIC;
begin
if Index < 0 then
Exit;
ComboBox1.Canvas.Font.Name := ComboBox1.Items[Index];
ComboBox1.Canvas.Font.Size := 16;
GetTextMetrics(ComboBox1.Canvas.Handle, tm);
Height := tm.tmHeight + tm.tmExternalLeading + 1;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
ComboBox1.Items := Screen.Fonts;
ComboBox1.ItemIndex := 0;
ComboBox1.Style := csOwnerDrawVariable;
end;
 
后退
顶部