...change the Background-Color of a Edit on a Focus Change?

Author: Thomas Greiner
Homepage: http://www.economx.com

Category: Misc

type
  
TForm1 = class(TForm)
    {...}
    
procedure OnFieldEnter(Sender: TObject);
    procedure OnFieldExit(Sender: TObject);
  end;

  {...}

const
  
clFocused = TColor($00FFFF);   // color for focused field
  
clBlurred = TColor($FFFFFF);   // color for blurred field


implementation


procedure 
TForm1.OnFieldEnter(Sender: TObject);
begin
  if 
(Sender is TCustomEdit) then
    
TEdit(Sender).Color := clFocused;
   // you may change all properties as desired when element is entered
end;

procedure TForm1.OnFieldExit(Sender: TObject);
begin
  if 
(Sender is TCustomEdit) then
    
TEdit(Sender).Color := clBlurred;
end;

(*
  Now you select every element you want to change color
  if entered on your form and add the OnFieldEnter/OnFieldExit
  procedure to the OnEnter/OnExit event.
*)

 

printed from
www.swissdelphicenter.ch
developers knowledge base