Home All Groups Group Topic Archive Search About

Complementary colors?

Author
14 Jun 2006 2:40 PM
R. MacDonald
Hello, Group,

If drawing on a control, it would be desirable to select a colour that
significantly differs from the control's background colour.  Is there a
standard (or preferred) way to programmatically select a complementary
color at run time?

Thanks in advance for any suggestions.

Cheers,
Randy

Author
14 Jun 2006 8:19 PM
Göran_Andersson
I would use the GetBrightness method on the color to determine if it's
closer to black or write, and use the other.

The complementary color could be calculated using:

Color.FromArgb(theColor.ToArgb() xor 0x00ffffff)

That doesn't work for all colors, though. The complementary color for
50% gray is 50% gray...

R. MacDonald wrote:
Show quoteHide quote
> Hello, Group,
>
> If drawing on a control, it would be desirable to select a colour that
> significantly differs from the control's background colour.  Is there a
> standard (or preferred) way to programmatically select a complementary
> color at run time?
>
> Thanks in advance for any suggestions.
>
> Cheers,
> Randy
Author
15 Jun 2006 9:27 AM
R. MacDonald
Hello, Göran,

Thanks for the suggestion about GetBrightness.  Looking at this I see
that there are also GetHue and GetSaturation methods that I might be
able to apply to this requirement.

Cheers,
Randy

Göran Andersson wrote:
Show quoteHide quote
> I would use the GetBrightness method on the color to determine if it's
> closer to black or write, and use the other.
>
> The complementary color could be calculated using:
>
> Color.FromArgb(theColor.ToArgb() xor 0x00ffffff)
>
> That doesn't work for all colors, though. The complementary color for
> 50% gray is 50% gray...
>
> R. MacDonald wrote:
>
>> Hello, Group,
>>
>> If drawing on a control, it would be desirable to select a colour that
>> significantly differs from the control's background colour.  Is there
>> a standard (or preferred) way to programmatically select a
>> complementary color at run time?
>>
>> Thanks in advance for any suggestions.
>>
>> Cheers,
>> Randy