Focused 是 Delphi 中许多可视化组件的一种方法。如果对象有 Focus,则此方法返回True, 否则 返回 False 。
TWinControl.Focused : Boolean;
当组件获得焦点时,它可以接收可用的键盘事件。例如:如果一个 Button 有 Focus,我们按下Enter 键 或 空格键 ,OnClick事件将会触发 。
以下示例是一个函数,它返回具有焦点的组件的名称:
function ActiveControl() : String;
var
I: Integer;
vControlActive: TWinControl;
begin
Result := '';
for I := 0 to ControlCount - 1 do
begin
if (Controls[I] is TWinControl) then
if (Controls[I] as TWinControl).Focused then
vControlActive := TWinControl(Controls[I]);
end;
if (vControlActive <> nil) then
begin
Result := vControlActive.Name;
end
end;
Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号
执行时间: 0.09427809715271 seconds