gpt4 book ai didi

delphi - 查找用户可见的所有控件

转载 作者:行者123 更新时间:2023-12-03 14:46:18 24 4
gpt4 key购买 nike

如何找到表单上当前用户可见的所有控件?即列出所有可以通过选项卡打开且不会从 View 中隐藏的控件(例如,在不可见的选项卡表上)。

最佳答案

由于您写道要列出可以使用 Tab 键访问的控件,因此我假设您正在谈论窗口控件。

那么你就可以简单地做

procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
begin
for i := 0 to ComponentCount - 1 do
if Components[i] is TWinControl then
if TWinControl(Components[i]).CanFocus then
Memo1.Lines.Add(Components[i].Name)
end;

如果您知道该表单拥有其所有子控件且没有其他控件。否则,你必须这样做

procedure AddVisibleChildren(Parent: TWinControl; Memo: TMemo);
var
i: Integer;
begin
for i := 0 to Parent.ControlCount - 1 do
if Parent.Controls[i] is TWinControl then
if TWinControl(Parent.Controls[i]).CanFocus then
begin
Memo.Lines.Add(Parent.Controls[i].Name);
AddVisibleChildren(TWinControl(Parent.Controls[i]), Memo);
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
AddVisibleChildren(Self, Memo1);
end;

关于delphi - 查找用户可见的所有控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12475974/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com