Ir para conteúdo
  • Cadastre-se

dev botao

analise de componente focus color


  • Este tópico foi criado há 923 dias atrás.
  • Talvez seja melhor você criar um NOVO TÓPICO do que postar uma resposta aqui.

Recommended Posts

Boa tarde a todos,

estive procurando um componente para mudar a cor dos edits memo etc, não encontrei então fiz um, mais gostaria da ajuda de vocês mestres de componentes para poder analisar para ver se esta tudo certo ou ate usar a ideia para criar um para o acbr!

 

{
    DWinControlFocusColor - Mudando as cores no focus em seus programas Delphi
    Copyright (C) 2021 DfoxSys

    Email: [email protected]
}
unit DWinControlFocusColor;

interface

uses
  Windows, Vcl.Forms, Vcl.Controls, Vcl.Dialogs, Messages, SysUtils, StrUtils, Classes, Vcl.Graphics,  Vcl.StdCtrls;

type
  TCloneWinControl = class(TWinControl);

type
  TDWinControlFocusColor = class(TComponent)
  private
    {Private Declarations}
    FFormOwner: TForm;
    FOldOnDestroy : TNotifyEvent;
    FOldOnCreate : TNotifyEvent;
    FAbout: string;
    FAtivo: Boolean;
    FEnterColor : TColor;
    FExitColor : TColor;
    procedure SetEnterColor(const Value: TColor);
    procedure SetExitColor(const Value: TColor);
    procedure SetAtivo(const Value: Boolean);
  protected
    {Protected Declarations}
  public
    {Public Declarations}
    Constructor Create(AOwner: TComponent); override;
    Destructor Destroy; override;
    procedure ControlChange(Sender: TObject);
    procedure DOnDestroy(Sender: TObject);
    procedure DOnCreate(Sender: TObject);
  published
    {Published Declarations}
    property About: string read FAbout;
    property Ativo: Boolean read FAtivo write SetAtivo default false;
    property EnterColor: TColor read FEnterColor write SetEnterColor default $00AEFFFF;
    property ExitColor: TColor read FExitColor write SetExitColor default clWindow;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('DfoxSys', [TDWinControlFocusColor]);
end;

procedure TDWinControlFocusColor.ControlChange(Sender: TObject);
var I: Integer;
begin
  for I := 0 to Owner.ComponentCount -1 do
  begin
    if (Owner.Components[I] is TWinControl)
    and not (ContainsText(Owner.Components[I].ClassName , 'Combo'))
    and not (ContainsText(Owner.Components[I].ClassName , 'Panel')) then
    begin
      if TCloneWinControl(Owner.Components[I]).Focused then
        TCloneWinControl(Owner.Components[I]).Color := FEnterColor
      else
        TCloneWinControl(Owner.Components[I]).Color := FExitColor;
    end;
  end;
end;

Destructor TDWinControlFocusColor.Destroy;
begin

  inherited Destroy;
end;

procedure TDWinControlFocusColor.DOnCreate(Sender: TObject);
begin
  try
    if  FAtivo then
    begin
      if not (Sender is TForm) then
        exit ;
      Screen.OnActiveControlChange := ControlChange;
    end;
  finally
    if Assigned(FOldOnCreate) then
      FOldOnCreate(Sender);
  end;
end;

procedure TDWinControlFocusColor.DOnDestroy(Sender: TObject);
begin
  try
    if  FAtivo then
    begin
      if not (Sender is TForm) then
        exit ;
      Screen.OnActiveControlChange := nil;
    end;
  finally
    if Assigned(FOldOnDestroy) then
      FOldOnDestroy(Sender);
  end;
end;

procedure TDWinControlFocusColor.SetAtivo(const Value: Boolean);
begin
  FAtivo := Value;
end;

procedure TDWinControlFocusColor.SetEnterColor(const Value: TColor);
begin
  FEnterColor := Value;
end;

procedure TDWinControlFocusColor.SetExitColor(const Value: TColor);
begin
  FExitColor := Value;
end;

Constructor TDWinControlFocusColor.Create(AOWner: TComponent);
var
  RealOwner: TComponent;
begin
  inherited;

  FFormOwner  := nil;
  FAbout      := '(c) 2021 Dfox Inc, ver 1.0.0.0';
  FAtivo      := False;
  FEnterColor := $00AEFFFF;
  FExitColor  := clWindow;

  if (not Assigned(FFormOwner)) then
  begin
    RealOwner := Owner;
    while Assigned(RealOwner) and (not (RealOwner is TCustomForm)) do
      RealOwner := RealOwner.Owner;

    FFormOwner := TForm(RealOwner);
    { Salvando estado das Propriedades do Form, que serão modificadas }
    with FFormOwner do
    begin
       FOldOnDestroy := OnDestroy;
       FOldOnCreate  := OnCreate;
    end ;
    if not (csDesigning in ComponentState) then
    begin
      with TForm(Owner) do
      begin
        OnDestroy := DOnDestroy;
        OnCreate  := DOnCreate;
      end;
    end;
  end;
end;

end.

 

Link para o comentário
Compartilhar em outros sites

  • Este tópico foi criado há 923 dias atrás.
  • Talvez seja melhor você criar um NOVO TÓPICO do que postar uma resposta aqui.

Crie uma conta ou entre para comentar

Você precisar ser um membro para fazer um comentário

Criar uma conta

Crie uma nova conta em nossa comunidade. É fácil!

Crie uma nova conta

Entrar

Já tem uma conta? Faça o login.

Entrar Agora
×
×
  • Criar Novo...

Informação Importante

Colocamos cookies em seu dispositivo para ajudar a tornar este site melhor. Você pode ajustar suas configurações de cookies, caso contrário, assumiremos que você está bem para continuar.

The popup will be closed in 10 segundos...