Código
interface
uses
Windows, Messages, SysUtils, Variants, Graphics, Controls, Forms,
Dialogs, Mask, DBCtrls, StdCtrls, Classes;
type
TForm1 = class(TForm)
Edit1: TEdit;
DBEdit1: TDBEdit;
procedure CorZe(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
mComponAnt: TComponent;
implementation
{$R *.dfm}
procedure TForm1.CorZe(Sender: TObject);
var
mComFoco, mSemFoco, mDesativado: TColor;
begin
mDesativado:= clBtnFace; // cor para quando o componente estiver desativado ou campos somente leitura...
mSemFoco:= clWindow; // cor para quando o componente estiver sem Foco
mComFoco:= clYellow; // cor para quando o componente estiver Com Foco
if TDBEdit(ActiveControl).Color <> mDesativado then
begin
if Assigned(mComponAnt) then
if TDBEdit(mComponAnt).Color <> mDesativado then TDBEdit(mComponAnt).Color:= mSemFoco; // cor sem foco
if (ActiveControl is TEdit) or
(ActiveControl is TDBEdit) or
(ActiveControl is TDBCheckBox) or
(ActiveControl is TDBComboBox) or
(ActiveControl is TComboBox) or
(ActiveControl is TDBLookupComboBox) or
(ActiveControl is TEdit) then
begin
TDBEdit(ActiveControl).Color := mComFoco; // cor com foco
mComponAnt := ActiveControl;
end;
end;
end;
{ Esta Procedure não tira a cor de componentes que ja estejam na cor somente leitura...}
procedure TForm1.FormActivate(Sender: TObject);
begin
Screen.OnActiveControlChange := CorZe;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Screen.OnActiveControlChange := nil;
end;
end.
Planeta Delphi - www.planetadelphi.com.br - Todos os direitos reservados | Copyright 2001-2009