Hat die ListBox nicht sogar ne Property Namens ScrollWidth?
Delphi-Quellcode:
procedure SetScrollWidth(ListBox: TListBox);
var
DC: HDC;
Size: TSize;
w, i, offset: Integer;
begin
offset := 2 * GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXVSCROLL);
with ListBox
do
begin
DC := GetDC(
Handle);
try
SelectObject(
DC, Font.Handle);
w := 0;
for i := 0
to Items.Count - 1
do
begin
if GetTextExtentPoint32(
DC, PChar(Items[i]),
StrLen(PChar(Items[i])), Size)
then
if w < Size.cx + offset
then
w := Size.cx + offset;
end;
ScrollWidth := w;
finally
ReleaseDC(
Handle,
DC);
end;
end;
end;
mal irgendwo durch Zufall gefunden (wenn nicht sogar hier)