Possible Duplicate:
How do I invert a colour?
Is it possible to find the opposing color for a given rgb combo? For example I have the following in a basic app.
myColor red = new myColor(0, true), green = new myColor(0, true), blue = new myColor(0, true), theColor;
Random rand = new Random(DateTime.Now.Millisecond);
int color = 0;
void timer_Tick(object sender, EventArgs e)
{
switch (color)
{
case 0: theColor = red; break;
case 1: theColor = green; break;
case 2: theColor = blue; break;
}
if (theColor.Up)
{
theColor.Value += 0.01F;
if (theColor.Value + 0.01F > 1) { theColor.Up = false; color = rand.Next(3); }
}
else if (!theColor.Up)
{
theColor.Value -= 0.01F;
if (theColor.Value - 0.01F < 0) { theColor.Up = true; color = rand.Next(3); }
}
label1.Text = red.Value + Environment.NewLine + green.Value + Environment.NewLine + blue.Value;
FadeBackground(red.Value, green.Value, blue.Value);
}
void FadeBackground(float red, float green, float blue)
{
BackColor = Color.FromArgb((int)((1 - red) * 255), (int)((1 - green) * 255), (int)((1 - blue) * 255));
label1.ForeColor = BackColor;
//label1.BackColor;
}
class myColor
{
public myColor(float value, bool up)
{
Value = value;
Up = up;
}
public float Value;
public bool Up;
}
But I'd like to be able to change the background color of the label so it's always the opposite, or an opposing, color of whatever the background is.
Thanks in advance and I hope this makes sense.