procedure TForm1.Button1Click(Sender: TObject);
var a,bb:integer;
begin
bb:= 0;
for a:= 0 to Listbox1.Items.Count- 1 do
begin
if bb<listBox1.Canvas.TextWidth(Listbox1.Items[a]) then
bb:=Listbox1.Canvas.TextWidth(Listbox1.Items[a]);
end;
SendMessage(Listbox1.Handle,LB_sethorizontalextent,bb+ 2, 0); //添加水平滚动条
end;
var a,bb:integer;
begin
bb:= 0;
for a:= 0 to Listbox1.Items.Count- 1 do
begin
if bb<listBox1.Canvas.TextWidth(Listbox1.Items[a]) then
bb:=Listbox1.Canvas.TextWidth(Listbox1.Items[a]);
end;
SendMessage(Listbox1.Handle,LB_sethorizontalextent,bb+ 2, 0); //添加水平滚动条
end;
运行结果如下