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;
3条答案
按热度按时间pgccezyw1#
s6fujrry2#
设置列表框的Columns属性以使用多个列和水平滚动条。诀窍是在代码中根据列表框的宽度和项目的宽度以及高度的变化来调整Columns的值,这取决于您的需要。
piztneat3#
下面是一个可以为您完成此任务的组件:(摘自原始来源:Rx库)(在 Delphi 5中测试)