Author: Tomas Rutkauskas
I have a TEdit control and there are two color properties I wish to set:
TEdit.Color and TEdit.Font.Color. I did something like
TEdit.Color := clBlack
TEdit.Font.Color := TEdit.Color xor $7FFFFFFF;
but TEdit.Font.Color doesn't show as contrast of TEdit.Color. Can anybody advise on
that. I wish to make the TEdit.Color and TEdit.Font.Color always contrast to each
other. My application allows the user to change the TEdit.color at runtime.
Answer:
Try this one:
1 function InverseColor(color: TColor): TColor;
2 var3 rgb_: TColorRef;
4 5 function Inv(b: Byte): Byte;
6 begin7 if b > 128 then8 result := 0
9 else10 result := 255;
11 end;
12 13 begin14 rgb_ := ColorToRgb(color);
15 rgb_ := RGB(Inv(GetRValue(rgb_)), Inv(GetGValue(rgb_)), Inv(GetBValue(rgb_)));
16 Result := rgb_;
17 end;