Mega Code Archive

 
Categories / Delphi / Graphic
 

How to change the Background Color of a Edit on a Focus Change

Title: How to change the Background-Color of a Edit on a Focus Change 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. *)