我有用listbox做的,其实稍加修改即可。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
ListBox1: TListBox;
procedure FormCreate(Sender: TObject);
procedure ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
procedure ListBox1MeasureItem(Control: TWinControl; Index: Integer;
var Height: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
ListBox1.Items := Screen.Fonts;
end;
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
with ListBox1 do
begin
Canvas.Brush.Color := clWhite;
Canvas.FillRect(Rect);
Canvas.Font.Name := Items[Index];
if odSelected in State then
Canvas.Brush.Color := clHighLight
else
Canvas.Brush.Color := clWhite;
Canvas.TextOut(Rect.Left, Rect.Top, Items[Index]);
end;
end;
procedure TForm1.ListBox1MeasureItem(Control: TWinControl; Index: Integer;
var Height: Integer);
begin
ListBox1.Canvas.Font.Name := ListBox1.Items[Index];
Height := 2 + ListBox1.Canvas.TextHeight(ListBox1.Items[Index]);
end;
end.
把listbox改为combobox即可