procedure HorScrollBar(ListBox: TListBox);
var
i, w: Integer;
maxwidth: Integer;
begin
maxwidth := 0;
// Get largest item
for i := 0 to ListBox.Items.Count – 1 do
with ListBox do begin
w := Canvas.TextWidth(Items
);
if w > maxwidth then
maxwidth := w;
end;
SendMessage(ListBox.Handle, LB_SETHORIZONTALEXTENT, maxwidth + GetSystemMetrics(SM_CXFRAME), 0);
SetWindowLong(ListBox.Handle, GWL_STYLE, GetWindowLong(ListBox.Handle, GWL_STYLE) or WS_HSCROLL);
SetWindowPos(ListBox.Handle, 0, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOMOVE or SWP_NOACTIVATE or SWP_NOZORDER or SWP_NOCOPYBITS or SWP_NOSENDCHANGING or SWP_NOREPOSITION or SWP_FRAMECHANGED);
end;