獲取Delphi焦點位置的方法,及所在的控件、以及如何通過控件名稱訪問控件並賦值


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

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM