Aprovechando que no están mis papás aquí te mando un ejemplo completito:
Código:
unit FocusEdit;
interface
uses
SysUtils, Classes, Controls, StdCtrls, Graphics;
type
TFocusEdit = class(TEdit)
private
FFocusColor: TColor;
FNormalColor: TColor;
procedure SetFocusColor(const Value: TColor);
protected
procedure DoEnter; override;
procedure DoExit; override;
public
constructor Create(AOwner: TComponent); override;
published
property FocusColor: TColor read FFocusColor write SetFocusColor default clInfoBk;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('ClubDelphi', [TFocusEdit]);
end;
{ TFocusEdit }
constructor TFocusEdit.Create(AOwner: TComponent);
begin
inherited;
FFocusColor := clInfoBk;
end;
procedure TFocusEdit.DoEnter;
begin
inherited;
FNormalColor := Color;
Color := FFocusColor;
end;
procedure TFocusEdit.DoExit;
begin
inherited;
Color := FNormalColor;
end;
procedure TFocusEdit.SetFocusColor(const Value: TColor);
begin
if FFocusColor <> Value then
begin
FFocusColor := Value;
if Self.Focused then
begin
FNormalColor := Color;
Color := FFocusColor;
end;
end;
end;
end.
La componente TFocusEdit agrega la propiedad FocusColor donde le pones el color que desees cuando tome el foco (por defecto clBkInfo = amarillo pálido). Sólo colocas una de éstas en el formulario y ¡listo! el control toma el color de FocusControl cuando gana el foco y recupera el color normal (propiedad Color heredada) cuando lo pierde.
// Saludos