Te quedo muy bien. Aprovechando que tengo un poco de tiempo libre (mi mujer y mi hijo no estan por un dia
) te hice unos cuantos retoques, espero que no te moleste.
Agregue colores por defecto, un evento cuando se produce el cambio de foco y reescribi el metodo ScreenActiveControlChange.
Código Delphi
[-]unit BRGFocusAdmin;
interface
uses
SysUtils, Classes, Graphics, StdCtrls, ComCtrls, Controls, Forms;
type
TBRGFocusAdmin = class(TComponent)
private
FTag: integer;
FColorConFoco: TColor;
FColorSinFoco: TColor;
FPierdeFoco, FTieneFoco: TWinControl; FOnFocusChange: TNotifyEvent;
procedure ScreenActiveControlChange(Sender: TObject);
protected
public
Procedure AplicarColor(Color: TColor; Componente: TWinControl);
constructor Create(AOwner : TComponent); override;
destructor Destroy; override;
published
property Tag: integer read FTag write FTag;
property ColorConFoco: TColor read FColorConFoco write FColorConFoco;
property ColorSinFoco: TColor read FColorSinFoco write FColorSinFoco;
property OnFocusChange: TNotifyEvent read FOnFocusChange write FOnFocusChange;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('BRG', [TBRGFocusAdmin]);
end;
constructor TBRGFocusAdmin.Create(AOwner : TComponent);
begin
inherited Create(AOwner);
Screen.OnActiveControlChange := ScreenActiveControlChange;
FColorConFoco := clSkyBlue;
FColorSinFoco := clWindow;
end;
destructor TBRGFocusAdmin.Destroy;
begin
Screen.OnActiveControlChange := nil;
inherited;
end;
procedure TBRGFocusAdmin.ScreenActiveControlChange(Sender: TObject);
begin
FPierdeFoco := FTieneFoco;
FTieneFoco := Screen.ActiveControl;
if FPierdeFoco <> nil then
Self.AplicarColor(FColorSinFoco, FPierdeFoco);
if FTieneFoco <> nil then
begin
self.AplicarColor(FColorconFoco, FTieneFoco);
FTag := self.Tag;
end else
FTag := 0;
if Assigned(FOnFocusChange) then FOnFocusChange(Self);
end;
Procedure TBRGFocusAdmin.AplicarColor(Color :TColor; Componente: TWinControl);
begin
try
if (Componente is TCustomEdit) then (Componente as TEdit).Color := Color;
if (Componente is TDateTimePicker) then (Componente as TDateTimePicker).Color:= Color;
if (Componente is TCustomMemo) then (Componente as TMemo).Color:= Color;
if (Componente is TCustomComboBox) then (Componente as TComboBox).Color:= Color;
(Componente as TWinControl).Repaint;
except
end;
end;
end.