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
