Prev: How to use the WebBrowser control to open an Office document
Next: Does anyone still use vbAdvance?
From: Claire on 5 Feb 2010 21:32 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 5 Feb 2010 21:54 "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 5 Feb 2010 22:14 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 5 Feb 2010 22:30 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 5 Feb 2010 23:46 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" >
|
Next
|
Last
Pages: 1 2 3 Prev: How to use the WebBrowser control to open an Office document Next: Does anyone still use vbAdvance? |