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).
Asked
Active
Viewed 9,799 times
1

Kromster
- 7,181
- 7
- 63
- 111

Koushik Halder
- 445
- 1
- 9
- 15
2 Answers
5
This is not supported by the standard TEdit
. You could set the edit to ReadOnly instead of Disabled - this way the font color is preserved but user can't change the value of the edit. Ie to "disable" the edit
Edit1.ReadOnly := True;
Edit1.Font.Color := clBlue;
and to enable it again
Edit1.ReadOnly := False;
Edit1.Font.Color := clWindowText;

ain
- 22,394
- 3
- 54
- 74
-
I only need to set Disbled TEdit Font Color it may be ReadOnly or not. I Googled, some solutions are there, but not understandable to me. – Koushik Halder Jan 08 '12 at 08:45
-
Setting the `TEdit.Enabled` property to `False` implicitally makes the edit field read-only to the user. So there really is no need to use the `TEdit.Enabled` property when the `TEdit.ReadOnly` property accomplishes the same effect. I use this approach in my apps all the time, it works fine. I even take it a step further by changing the `TEdit.Color` property whenever I change the `TEdit.ReadOnly` property so the user can visually see that the edit field has been "disabled", eg: `Edit1.Color := clBtnFace; Edit1.ReadOnly := True;` and `Edit1.Color := clWindow; Edit1.ReadOnly := False;` – Remy Lebeau Jan 09 '12 at 02:17
3
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;

Max Williams
- 821
- 1
- 7
- 13