Re: adding a horzontail scroll bar to a list box



See the LB_SETHORIZONTALEXTENT windows message in Win32 help..

procedure SetListBoxHorzScroll(ListBox : TListBox);
var
i, StrWidth, MaxWidth, LBScrollWidth : integer;
begin
{get max text width}
MaxWidth := 0;
with ListBox do begin
for i := 0 to {.}Items.Count - 1 do begin
StrWidth := {.}Canvas.TextWidth({.}Items[i]);
if StrWidth > MaxWidth then
MaxWidth := StrWidth;
end; {for i := 0 to Items.Count - 1}
{calculate scroll width}
LBScrollWidth := MaxWidth + 4; // plus 4 for borders;
{set scroll width}
{.}Perform(LB_SETHORIZONTALEXTENT, LBScrollWidth, 0);
end;
end;

Alan Lloyd

.