2005. augusztus 2., kedd

Invert the color of a TEdit


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.


Try this one:

function InverseColor(color: TColor): TColor;
  rgb_: TColorRef;

  function Inv(b: Byte): Byte;
    if b > 128 then
      result := 0
      result := 255;

  rgb_ := ColorToRgb(color);
  rgb_ := RGB(Inv(GetRValue(rgb_)), Inv(GetGValue(rgb_)), Inv(GetBValue(rgb_)));
  Result := rgb_;

Nincsenek megjegyzések:

Megjegyzés küldése