更正:
procedure TForm1.FormCreate(Sender: TObject);
var
i,j,count,lent, MaxWidth: integer;
str,cstr:string;
begin
MaxWidth := round(listbox1.ClientWidth/13) ;
for i := 0 to ListBox1.Items.Count - 1 do
begin
showmessage(ListBox1.Items.Strings[i]);
// maxwidth:=ListBox1.Canvas.TextWidth(ListBox1.Items.Strings[i]);
if MaxWidth < ListBox1.Canvas.TextWidth(ListBox1.Items.Strings[i]) then
str:=ListBox1.Items.Strings[i];
// lent:=length(str);
lent:=round(ListBox1.Canvas.TextWidth(ListBox1.Items.Strings[i])/13);
count:=round(lent/maxwidth);
ListBox1.Items.Strings[i]:=Copy(str,1,MaxWidth);
for j:=1 to count do
begin
cstr:=Copy(str,maxwidth+1,maxwidth*j+1);
ListBox1.Items.Strings[i+j]:=Copy(str,maxwidth+1,maxwidth);
maxwidth:=maxwidth*j+1;
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i,count,lent, MaxWidth: integer;
str:string;
begin
MaxWidth := listbox1.ClientWidth ;
for i := 0 to ListBox1.Items.Count - 1 do
if MaxWidth < ListBox1.Canvas.TextWidth(ListBox1.Items.Strings[i]) then
str:=ListBox1.Items.Strings[i];
lent:=length(str);
count:=(lent div maxwidth);
ListBox1.Items.Strings[i]:=Copy(str,1,MaxWidth);
ListBox1.Items.Strings[i+1]:=Copy(str,maxwidth+1,lent);
end;