Ver Mensaje Individual
  #8  
Antiguo 23-11-2006
Avatar de Crandel
[Crandel] Crandel is offline
Miembro Premium
 
Registrado: may 2003
Ubicación: Parana, Argentina
Posts: 1.475
Reputación: 23
Crandel Va por buen camino
muy bien !!!

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
    { Private declarations }
    FTag: integer;
    FColorConFoco: TColor;
    FColorSinFoco: TColor;
    FPierdeFoco, FTieneFoco: TWinControl; // a partir de WinControl pueden recibir el foco
    FOnFocusChange: TNotifyEvent;
    procedure ScreenActiveControlChange(Sender: TObject);
  protected
    { Protected declarations }
  public
    { Public declarations }
    Procedure AplicarColor(Color: TColor; Componente: TWinControl);
    constructor Create(AOwner : TComponent); override;
    destructor Destroy; override;
  published
    { Published declarations }
    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.
__________________
[Crandel]
Responder Con Cita