Category: Components
Title: Show a horizontal scrollbar in a Listbox
Date added: 15.03.2006
Hits: 4019
procedure HorScrollBar(ListBox: TListBox; MaxWidth: Integer);
var
i, w: Integer;
begin
if MaxWidth = 0
then
SendMessage(ListBox.Handle, LB_SETHORIZONTALEXTENT, MaxWidth, 0)
else
begin
{ get largest item }
for i := 0
to ListBox.Items.Count - 1 do
with ListBox do
begin
w := Canvas.TextWidth(Items[i]);
if w > MaxWidth
then
MaxWidth := w;
end;
SendMessage(ListBox.Handle, LB_SETHORIZONTALEXTENT,
MaxWidth + GetSystemMetrics(SM_CXFRAME), 0);
end;
end;