你指的是获得焦点时高亮吧
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
edt1: TEdit;
edt2: TEdit;
{定义了两个通用的高亮处理函数,供所有的TEdit组件公用}
procedure EditOnExit(Sender: TObject);
procedure EditOnEnter(Sender: TObject);
private
{ Private declarations }
FLastContrl: TWinControl; {获得高亮时,记下谁最后获得了高亮,以便离开时恢复}
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.EditOnEnter(Sender: TObject);
begin
{这里使用了ActiveControl来获取当前处于焦点的控件}
if ActiveControl is TEdit then
begin
(ActiveControl as TEdit).Color := clSkyBlue;
FLastContrl := ActiveControl;{记下是谁最后获得焦点}
end;
end;
procedure TForm1.EditOnExit(Sender: TObject);
begin
(FLastContrl as TEdit).Color := clWindow;{离开时恢复}
end;
end.
补充:对所有的TEdit,把它的OnEnter和OnExit事件关联到这两个函数,可以在任务管理器设置,也可以用代码,文本框多的时候用代码来得简一些