Delphi 获取焦点位置及所在控件的方法:
方法一,循环判断:
Var
I: Integer;
Begin
For I := 0 To ComponentCount - 1 Do //获取组件数量
Begin
If Components[I] Is TWinControl Then
Begin
If (Components[I] As TWinControl).Focused Then
Begin
Self.Caption := (Components[I] As TWinControl).Name;
Break;
End;
End;
End;
方法二,通过活动控件的名称判断:
Activecontrol.name //获取Delphi焦点所在的控件
方法三:
某个控件的name.Focused
已知控件名称访问控件并赋值:
var
Panel: TComponent;
begin
Panel := FindComponent("pnlToolbar");
If Panel is TPanel then
TPanel(Panel).Color := clSilver;
end;
创建时间:2019.08.05 更新时间:2020.01.08
来源:https://www.cnblogs.com/guorongtao/p/11301331.html