Search code examples
delphidelphi-xe2

Disabled TEdit Font Colour


I have an application having one TEdit which is disabled when the application runs. After some calculations it will be enabled. My requirement is to set the Font.Color of this disabled TEdit as Blue instead of Grey (Disabled Font Color).


Solution

  • See Peter Below's two suggestions for accomplishing your objective on Torry's Delphi Pages at this link. Judging from your comment about what you Googled, his first suggestion will be simpler for you to implement. Drop a TPanel on a form and drag a TEdit onto the TPanel (i.e., TPanel is TEdit's parent. Then drop a Button on the form to simulate when your calculations are done.

    procedure TForm1.btnToggleEnabledClick(Sender: TObject);
    begin
      if Panel1.Enabled then
      begin
        {Calcs are not done, so disable the TEdit}
        Panel1.Enabled := false;
        Edit1.Font.Color := clBlue;
        Edit1.Text := 'Calcs not done';
      end
      else
      begin
        {Calcs are done, so enable the TEdit}
        Panel1.Enabled := true;
        Edit1.Font.Color := clWindowText;
        Edit1.Text := 'Calcs all done';
      end;
    end;