因此,我想垂直中心的TListBox (而不是TListView)项目。
我可以使用TopIndex属性,但是如何完成整个过程。
如果条目较少,因此滚动条不出现,则不需要对中心,只有选择默认项才行。
就像这样:

发布于 2017-05-10 13:11:44

//IF YOU WANT TO SELECT THE CENTER ITEM
procedure TForm2.Center;
var VisibleItems : Integer;
begin
VisibleItems := ListBox1.ClientHeight div ListBox1.ItemHeight;
ListBox1.TopIndex := Trunc((ListBox1.Items.Count / 2) - (VisibleItems / 2));
if ListBox1.Items.Count > VisibleItems then
ListBox1.Selected[ListBox1.TopIndex + (VisibleItems div 2)] := True
else
ListBox1.Selected[ListBox1.Items.Count div 2] := True;
end;
//IF YOU WANT TO CENTER A ITEM
procedure TForm2.Center(Index : Integer);
var VisibleItems : Integer;
begin
VisibleItems := ListBox1.ClientHeight div ListBox1.ItemHeight;
if Index > VisibleItems then
ListBox1.TopIndex := Index - (VisibleItems div 2);
end;https://stackoverflow.com/questions/43892858
复制相似问题