OK
其实这个问题很好办,还是OwnerDraw 来个实例,放一个Listbox,加点ITEMS,将例中两个
事件句柄设置好,RUN!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, StdCtrls;
type
TForm1 = class(TForm)
ListBox1: TListBox;
procedure ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
procedure ListBox1MeasureItem(Control: TWinControl; Index: Integer;
var Height: Integer);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var Afont:tfont;
begin
with (Control as TListBox).Canvas do
begin
FillRect(Rect);
Brush.Style:=bsClear;
Font.Size:=10;
Font.Color:=clRed;
Font.Style:=Font.Style+[fsItalic];
TextOut(Rect.Left, Rect.Top, 'Item:'+ IntToStr(Index+1));
Font.Color:=ListBox1.font.Color;
Font.Style:=Font.Style-[fsItalic];
TextOut(Rect.Left+40, Rect.Top+16, (Control as TListBox).Items[Index]);
end;
end;
procedure TForm1.ListBox1MeasureItem(Control: TWinControl; Index: Integer;
var Height: Integer);
begin
Height:=-ListBox1.Font.Height;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
{初始化:设置OWNERDRAW}
ListBox1.Font.Size:=24;
ListBox1.Style:=lbOwnerDrawVariable;
end;
end.
很简单。;-)