可以参考一下这个函数:
// 为 Listbox 增加水平滚动条
procedure ListboxHorizontalScrollbar(Listbox: TCustomListBox);
var
i: Integer;
Width, MaxWidth: Integer;
begin
Assert(Assigned(Listbox));
MaxWidth := 0;
for i := 0 to Listbox.Items.Count - 1 do
begin
Width := Listbox.Canvas.TextWidth(Listbox.Items[i]) + 4;
if Width > MaxWidth then
MaxWidth := Width;
end;
if ListBox is TCheckListBox then
Inc(MaxWidth, GetSystemMetrics(SM_CXMENUCHECK) + 2);
SendMessage(Listbox.Handle, LB_SETHORIZONTALEXTENT, MaxWidth, 0);
end;