Peter said:
this gives the opposite of a color
TextBox1.ForeColor = Color.FromArgb(255 - TextBox1.BackColor.R, 255 -
TextBox1.BackColor.G, 255 - TextBox1.BackColor.B)
hth Peter
But that doesn't always give a contrasting colour as the OP wants. If
the color is close to 50% grey, the resulting colour with your method
will also be close to 50% grey.
Just off the top of my head, you could look at the greyvalue of the
color (20% red, 60% green, 20% blue) and then see if it's below 50%
grey, use white (or a very bright color) and if it's above 50% grey, use
black (or a dark color).
i.e.
dim nGrey,
nGrey = 0.2 * TextBox1.BackColor.R + 0.6 * TextBox1.BackColor.G + 0.2 *
TextBox1.BackColor.B
if nGrey>128 then
Texbox1.ForeColor(color.black)
Else
Texbox1.ForeColor(color.white)
Endif
btw those percentages come from the graphics world to convert color intp
greyscale, I didn't make them up.