Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing the disabled colour of a TEdit box

Status
Not open for further replies.

swelch

Programmer
Jun 18, 2002
1
GB
This is probably a silly question and the answer is obvious but I'm blowed if I can find it - How do you change the color of the font on a disabled TEdit box? Just specific ones not system wide.

Thanks
Steve
 
Steve,

By default, disabled edit controls are painted with a greyed text font. There are two basic choices:

1. Place the edit control in a container, like a tPanel, and then use something like this to manage the Font color of the edit box:

Code:
var
   cFontColor : TColor;
begin

   With Edit1 do
   begin
     if Parent.enabled then 
        cFontColor := clBlack
     else
        cFontColor := clRed;
     Font.Color := cFontColor;
   end;
end;

This is easy, but could (depending on your form and the version(s) of Windows your application run under) raise the resource requirements.

2. Create a new tEdit (or tCustomEdit) descendent that overrides the painting. There's a good starting place at it also handles the background color of the Edit control.

This is perhaps the best approach from an engineering persepctive; you'd simply use your new component for those edit boxes that need the font color changed.

Hope this helps...

-- Lance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top