changing color font in disabled edit box

Posted on 1998-12-28
Last Modified: 2013-12-03
is there a way of changing the color of the font in a disabled tedit control? i.e is it possible to have the contents displayed in something different than the grey color to show a disabled status ? (for ex: I want red font over white background when control is disabled)
Question by:fadyg
  • 2
LVL 17

Accepted Solution

inthe earned 50 total points
ID: 1353448
yes but it's quite tricky .
i post a component for you to to it cut n paste and save as DiscEdit.Pas then install component it will be on samples pallette :

unit DisCEdit;


  WinTypes, WinProcs, Messages, SysUtils, Classes, Graphics, Controls,

  TDisabledColorEdit = class(Tedit)
    { Private declarations }
    FEnabled: Boolean;
    FDisabledColor: Tcolor;
    FDisabledFontColor: TColor;
    FOldColor, FOldFontColor: TColor;

    Procedure SetEnabled( value: Boolean );
    Procedure SetDisabledColor( value: TColor );
    Procedure SetDisabledFontColor( value: TColor );
    Procedure SetReadOnly( value: Boolean );
    Function GetReadOnly: Boolean;
    { Protected declarations }
    { Public declarations }

    Constructor Create( aOwner: TComponent ); override;
    { Published declarations }

    property Enabled: Boolean read FEnabled write SetEnabled default true;
    property ReadOnly: Boolean read GetReadOnly write SetReadOnly default
    property DisabledColor: TColor read FDisabledColor write
    property DisabledFontColor: TColor read FDisabledFontColor write

procedure Register;


 Constructor TDisabledColorEdit.Create( aOwner: TComponent );
   FEnabled := True;
   FDisabledColor := clWindowText;
   FDisabledFontColor := clGrayText;
   inherited Create( aOwner );

 Procedure TDisabledColorEdit.SetEnabled( value: Boolean );
   If FEnabled <> value Then Begin
     inherited ReadOnly := not value;
     FEnabled := value;
     If value Then Begin
       Color := FOldColor;
       Font.Color := FOldFontColor;
     Else Begin
       FOldColor := Color;
       FOldFontColor := Font.Color;
       Color := FDisabledColor;
       Font.Color := FDisabledFontColor;

 Procedure TDisabledColorEdit.SetDisabledColor( value: TColor );
   If FDisabledColor <> value Then Begin
     If not FEnabled Then
       Color := value;
     FDisabledColor := value;

 Procedure TDisabledColorEdit.SetDisabledFontColor( value: TColor );
   If FDisabledFontColor <> value Then Begin
     If not FEnabled Then
       Font.Color := value;
     FDisabledFontColor := value;

 Procedure TDisabledColorEdit.SetReadOnly( value: Boolean );
   If FEnabled Then
     inherited ReadOnly := value;

 Function TDisabledColorEdit.GetReadOnly: Boolean;
   result := inherited ReadOnly;

procedure Register;
  RegisterComponents('Samples', [TDisabledColorEdit]);



Author Comment

ID: 1353449
thanks for your reply,
your component would work correctly but this would give me a control that can get the focus (even though you won't be able to change anything because it's a read-only).  What is needed is the exact same behaviour as diabled i.e. no focus.

any ideas ?
LVL 17

Expert Comment

ID: 1353450
ok to try this put my comp on a form and a button
give my comp some disabledcolors then on button click type this:

    GetWindowLong(DisabledColorEdit1.Handle,GWL_STYLE) or WS_DISABLED);

this will stop it from recieving focus
if you want it to recieve focus type this:

    GetWindowLong(DisabledColorEdit1.Handle,GWL_STYLE) and not WS_DISABLED);

Regards Barry


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
error 1.1 400 Bad request idhttp delphi 18 52
How to call a form that is in a DLL  from an application? 13 64
Downloading email attachments 2 66
Delphi...Split view - idea? 1 39
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now