Inverse color

  • Thread starter Thread starter William Stacey [MVP]
  • Start date Start date
W

William Stacey [MVP]

If user selects same forecolor as backcolor, I want to invert the forecolor
so they are not the same. Any ideas?
 
Take out the R, G, and B components of the backcolor, subtract each from
255, and use those new R, G, and B values for the forecolor. This works
almost all the time, except when the backcolor is close to the middle of the
range for the three components (128,128,128). In this problem case the
forecolor comes out about the same as the backcolor. So if you use this
technique, test for that case and do something different such as choosing an
arbitrary contrasting color.

Tom Dacon
Dacon Software Consulting
 
Thanks Tom.

--
William Stacey, MVP

Tom Dacon said:
Take out the R, G, and B components of the backcolor, subtract each from
255, and use those new R, G, and B values for the forecolor. This works
almost all the time, except when the backcolor is close to the middle of the
range for the three components (128,128,128). In this problem case the
forecolor comes out about the same as the backcolor. So if you use this
technique, test for that case and do something different such as choosing an
arbitrary contrasting color.

Tom Dacon
Dacon Software Consulting
 
Back
Top