From: Claire on
Hello,
I wonder if there is some way to automatically select contrasting
color to the color user's selected.
My problem is that my code allows user to select background color of the
textbox but not the foreground color.
Foreground color should be selected automatically contrasting the background
color.
Any idea appreciated,
Claire


From: C. Kevin Provance on

"Claire" <replyto(a)fra> wrote in message
news:%23hz9fStpKHA.3948(a)TK2MSFTNGP06.phx.gbl...
| Hello,
| I wonder if there is some way to automatically select contrasting
| color to the color user's selected.
| My problem is that my code allows user to select background color of the
| textbox but not the foreground color.
| Foreground color should be selected automatically contrasting the
background
| color.
| Any idea appreciated,

I did this some years back. It's kind of involved, so I'll point you in the
right direction.

Write (or find) a routine that will extract the Hue, Saturated and Luminance
variables from a long value representing your RBG color (that's the complex
part).

If the Luminance is greater than or equal to (240 / 2) then return a
forecolor of black, else return white (&HFFFFFF).

I don't know if that's how MSFT does it, but it's worked flawlessly in
production for years.


From: Claire on
Thank you, Kevin.
That is a good start.
I am using common dialog API and I can see those values:Hue, Sat & Lum
displayed in the dialog window.
Is there any way to to get those values through API?
Claire

"C. Kevin Provance" <*@*.*> wrote in message
news:On8M2etpKHA.4280(a)TK2MSFTNGP06.phx.gbl...
>
> "Claire" <replyto(a)fra> wrote in message
> news:%23hz9fStpKHA.3948(a)TK2MSFTNGP06.phx.gbl...
> | Hello,
> | I wonder if there is some way to automatically select
> contrasting
> | color to the color user's selected.
> | My problem is that my code allows user to select background color of the
> | textbox but not the foreground color.
> | Foreground color should be selected automatically contrasting the
> background
> | color.
> | Any idea appreciated,
>
> I did this some years back. It's kind of involved, so I'll point you in
> the
> right direction.
>
> Write (or find) a routine that will extract the Hue, Saturated and
> Luminance
> variables from a long value representing your RBG color (that's the
> complex
> part).
>
> If the Luminance is greater than or equal to (240 / 2) then return a
> forecolor of black, else return white (&HFFFFFF).
>
> I don't know if that's how MSFT does it, but it's worked flawlessly in
> production for years.
>
>


From: Jim Mack on
Claire wrote:
> Thank you, Kevin.
> That is a good start.
> I am using common dialog API and I can see those values:Hue, Sat &
> Lum displayed in the dialog window.
> Is there any way to to get those values through API?
> Claire

You don't need to go quite that far -- just calculate the luminance.
That's pretty simple:

Dim Y As Long, R As Long, etc

Y = (B * 28&) + (R * 77&) + (G * 151&)

Where BRG are the Blue, Red & Green components, with values from
0..255 each.

Y will be the Luminance value, from 0..65280.

If Y >= 32640, use Black as the forecolor. If less, use White.

--
Jim Mack
Twisted tees at http://www.cafepress.com/2050inc
"We sew confusion"

From: Claire on
Thank you.
It does work very well.
Claire

"Jim Mack" <jmack(a)mdxi.nospam.com> wrote in message
news:e8yBwytpKHA.3912(a)TK2MSFTNGP06.phx.gbl...
> Claire wrote:
>> Thank you, Kevin.
>> That is a good start.
>> I am using common dialog API and I can see those values:Hue, Sat &
>> Lum displayed in the dialog window.
>> Is there any way to to get those values through API?
>> Claire
>
> You don't need to go quite that far -- just calculate the luminance.
> That's pretty simple:
>
> Dim Y As Long, R As Long, etc
>
> Y = (B * 28&) + (R * 77&) + (G * 151&)
>
> Where BRG are the Blue, Red & Green components, with values from
> 0..255 each.
>
> Y will be the Luminance value, from 0..65280.
>
> If Y >= 32640, use Black as the forecolor. If less, use White.
>
> --
> Jim Mack
> Twisted tees at http://www.cafepress.com/2050inc
> "We sew confusion"
>