Showing posts with label Colour. Show all posts
Showing posts with label Colour. Show all posts

Tuesday, 2 April 2013

Retrieving a system color

I had a problem recently and needed to set a font colour depending what was set as a system colour, in Delphi this ended up being very easy. To get say the highlight colour just do the following:

GetSysColor(COLOR_HIGHLIGHT)

This returns the colour as a TColor, I then used this value in a previous function to determine whether is was light or dark and then set the font colour accordingly. This will require 'Windows' and 'Graphics' in the uses clause. The 'color_highlight' is a constant, go to where it is declared in the windows unit to see the other options.


Tuesday, 11 December 2012

Determine if a colour light

Below is a Delphi function to determine whether a colour is light, this is useful if a user can for example change the background colour of a control, you will need then to set the font colour correctly.


function ColourIsLight(Colour: TColor): boolean;
begin
    Colour := ColorToRGB(Colour);
    Result := ((Colour and $FF) + (Colour shr 8 and $FF) + (Colour shr 16 and    $FF)) >= $180;
end;