Ver Mensaje Individual
  #5  
Antiguo 21-04-2004
Avatar de roman
roman roman is offline
Moderador
 
Registrado: may 2003
Ubicación: Ciudad de México
Posts: 20.269
Reputación: 10
roman Es un diamante en brutoroman Es un diamante en brutoroman Es un diamante en bruto
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

Última edición por roman fecha: 21-04-2004 a las 05:43:09. Razón: Explicación
Responder Con Cita