procedure TForm1.FormCreate(Sender: TObject);
begin
Listbox1.Style := lbOwnerDrawVariable;
end;
procedure TForm1.ListBox1MeasureItem(Control: TWinControl; Index: Integer;
var Height: Integer);
var
cv: TCanvas;
H : HWND;
R : TRect;
begin
cv := TCanvas.Create;
try
cv.Handle := GetDeviceContext(H);
R := ListBox1.ClientRect;
Height := DrawText(cv.Handle,PChar(ListBox1.Items[Index]), -1, R, DT_WORDBREAK);
finally
cv.Free;
end;
end;
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
cv: TCanvas;
begin
cv:= Listbox1.Canvas;
cv.FillRect(Rect);
DrawText(cv.Handle, PChar(ListBox1.Items[Index]), -1, Rect, DT_LEFT+DT_TOP+DT_WORDBREAK);
Invalidate;
end;