我如何将 tpanel 对齐到列表视图项目的最底部
how do i align a tpanel to a very bottom of listview item
我尝试做的和这张图一样
我试过的东西panel1.top := ListView1.Items[i].position.Y;
但是这个技巧并没有成功,是否有可能在某些项目的底部对齐 Tpanel
添加了实际代码
procedure Ttestthreading.streamClick(Sender: TObject);
var
i, R: integer;
begin
if stream.Caption = 'stream' then
begin
for i := 0 to ListView1.Items.Count - 1 do
if ListView1.Items[i].SubItems[3] = IntToStr(UniqueID) then
begin
R := ListView1.Items[i].Index;
panel2.Top := ListView1.Items[i].Position.Y;
end;
ExchangeItems(ListView1, R, 0);
stream.Caption := 'stopstream';
panel2.Visible := true;
// start stream
end
else if stream.Caption = 'stopstream' then
begin
ExchangeItems(ListView1, R, 0);
stream.Caption := 'stream';
panel2.Visible := false;
// stopstream
end;
end;
制作一个新表格,复制此代码并将其粘贴到表格中
object ListView1: TListView
Left = 0
Top = 40
Width = 250
Height = 296
Anchors = [akLeft, akTop, akRight, akBottom]
Columns = <>
TabOrder = 0
end
object Panel1: TPanel
Left = 0
Top = 0
Width = 250
Height = 41
Anchors = [akLeft, akTop, akRight]
Caption = 'Panel1'
TabOrder = 1
end
首先我在设计时安排了这两个对象。然后我在两个对象上都设置了锚点。
如果您查看文档 http://docwiki.embarcadero.com/Libraries/XE2/en/Vcl.ComCtrls.TListItem.Position,您会发现 TListitem.Position 仅在 ListView 视图样式为 vsIcon 或 vsSmallIcon 时有效。
因此,与其使用 Position 属性,不如使用 DisplayRect 方法 http://docwiki.embarcadero.com/Libraries/XE2/en/Vcl.ComCtrls.TListItem.DisplayRect,其中 returns 呈现列表项的矩形。
我尝试做的和这张图一样
我试过的东西panel1.top := ListView1.Items[i].position.Y;
但是这个技巧并没有成功,是否有可能在某些项目的底部对齐 Tpanel
添加了实际代码
procedure Ttestthreading.streamClick(Sender: TObject);
var
i, R: integer;
begin
if stream.Caption = 'stream' then
begin
for i := 0 to ListView1.Items.Count - 1 do
if ListView1.Items[i].SubItems[3] = IntToStr(UniqueID) then
begin
R := ListView1.Items[i].Index;
panel2.Top := ListView1.Items[i].Position.Y;
end;
ExchangeItems(ListView1, R, 0);
stream.Caption := 'stopstream';
panel2.Visible := true;
// start stream
end
else if stream.Caption = 'stopstream' then
begin
ExchangeItems(ListView1, R, 0);
stream.Caption := 'stream';
panel2.Visible := false;
// stopstream
end;
end;
制作一个新表格,复制此代码并将其粘贴到表格中
object ListView1: TListView
Left = 0
Top = 40
Width = 250
Height = 296
Anchors = [akLeft, akTop, akRight, akBottom]
Columns = <>
TabOrder = 0
end
object Panel1: TPanel
Left = 0
Top = 0
Width = 250
Height = 41
Anchors = [akLeft, akTop, akRight]
Caption = 'Panel1'
TabOrder = 1
end
首先我在设计时安排了这两个对象。然后我在两个对象上都设置了锚点。
如果您查看文档 http://docwiki.embarcadero.com/Libraries/XE2/en/Vcl.ComCtrls.TListItem.Position,您会发现 TListitem.Position 仅在 ListView 视图样式为 vsIcon 或 vsSmallIcon 时有效。
因此,与其使用 Position 属性,不如使用 DisplayRect 方法 http://docwiki.embarcadero.com/Libraries/XE2/en/Vcl.ComCtrls.TListItem.DisplayRect,其中 returns 呈现列表项的矩形。