看看控件的Focused是否为true,遍历所有控件就可以了,下面是Delphi帮助中的示例:
procedure TForm1.ColorControl(Sender: TObject);
var
I : Integer;
ControlColor: TColor;
begin
for I:= 0 to ControlCount -1 do begin
ControlColor :=clNormalForeground;
if Controls[I] is TWidgetControl then
if (Controls[I] as TWidgetControl).Focused then
ControlColor := clRed
if Controls[I] is TEdit then
(Controls[I] as TEdit).Color := ControlColor
elseif Controls[I] is TMemo then
(Controls[I] as TMemo).Color := ControlColor
elseif Controls[I] is TButton then
(Controls[I] as TButton).Font.Color := ControlColor;
end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
Screen.OnActiveControlChange := ColorControl;
end;
procedure TForm1.ColorControl(Sender: TObject);
var
I : Integer;
ControlColor: TColor;
begin
for I:= 0 to ControlCount -1 do begin
ControlColor :=clNormalForeground;
if Controls[I] is TWidgetControl then
if (Controls[I] as TWidgetControl).Focused then
ControlColor := clRed
if Controls[I] is TEdit then
(Controls[I] as TEdit).Color := ControlColor
elseif Controls[I] is TMemo then
(Controls[I] as TMemo).Color := ControlColor
elseif Controls[I] is TButton then
(Controls[I] as TButton).Font.Color := ControlColor;
end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
Screen.OnActiveControlChange := ColorControl;
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货