tedit font color change in enabled=false state

Hi there,

I'd like to change the font color of a tedit component when the enabled flag is set to false. I have found several solutions here so change the background color, however it seems that the font color, depending on the background color is either set to grey or black, however I want it set to clBlack even when enabled set to false.
IshwoodAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Graham HirstIT EngineerCommented:
I think you need to use the SetSysColors API function.
0
AmigoJackCommented:
what FSIFM suggests also involves that all other windows then will use that color, be aware of that.

but when i understood you right, you could also live with the following workaround which i used always: instead of setting enabled:= false set readonly:= true - this has two advantages: the user can still select the content and copy it to clipboard AND youre able to set both the background and textcolor fully according to your needs.
0
mokuleCommented:
If You want to avoid grey font color in disabled Edit place it on a Panel.
Then don't disable Edit but disable Panel.
0
Eddie ShipmanAll-around developerCommented:
This allows you to set the Font AND background color of all disabled edits on the form...

unit udedits;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TEdit = class(StdCtrls.TEdit)
  private
    FEnabled: Boolean;
    FDisabledColor: TColor;
    FDisabledFontColor: TColor;
    FOldColor, FOldFontColor: TColor;
    procedure SetEnabled(AValue: Boolean);
    procedure SetDisabledColor(AValue: TColor);
    procedure SetDisabledFontColor(AValue: TColor);
    procedure SetReadOnly(AValue: Boolean);
    function GetReadOnly: Boolean;
  protected
    { Protected declarations }
  public
    { Public declarations }

    constructor Create(AOwner: TComponent); override;
  published
    { Published declarations }
    property Enabled: Boolean read FEnabled write SetEnabled default True;
    property ReadOnly: Boolean read GetReadOnly write SetReadOnly default False;
    property DisabledColor: TColor read FDisabledColor
                                   write SetDisabledColor;
    property DisabledFontColor: TColor read FDisabledFontColor
                                       write SetDisabledFontColor;
  end;

  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


constructor TEdit.Create(AOwner: TComponent);
begin
  FEnabled := True;
  FDisabledColor := clYellow;
  FDisabledFontColor := clBlack;
  inherited Create(AOwner);
end;

procedure TEdit.SetEnabled(AValue: Boolean);
begin
  if FEnabled <> AValue then
  begin
    inherited ReadOnly := not AValue;
    FEnabled := AValue;
    if AValue then
    begin
      Color := FOldColor;
      Font.Color := FOldFontColor;
    end
    else
    begin
      FOldColor := Color;
      FOldFontColor := Font.Color;
      Color := FDisabledColor;
      Font.Color := FDisabledFontColor;
    end;
  end;
end;

procedure TEdit.SetDisabledColor(AValue: TColor);
begin
  if FDisabledColor <> AValue then
  begin
    if not FEnabled then
      Color := AValue;
    FDisabledColor := AValue;
  end;
end;

procedure TEdit.SetDisabledFontColor(AValue: TColor);
begin
  if FDisabledFontColor <> AValue then
  begin
    if not FEnabled then
      Font.Color := AValue;
    FDisabledFontColor := AValue;
  end;
end;

procedure TEdit.SetReadOnly(AValue: Boolean);
begin
  if FEnabled then
    inherited ReadOnly := AValue;
end;

function TEdit.GetReadOnly: Boolean;
begin
  Result := inherited ReadOnly;
end;

end.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
saravananvgCommented:
Hello Sir,

  Instead of disabling why dont you set the readonly property to true.

with regards,
padmaja.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Fonts Typography

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.