I'm trying to change the fore colour of my labels if they are less than the value of another label by -2
Example, on my form I have 11 labels then I have another label lets say called "total" that will contain a value for instance 100.
I'm trying to achieve a formula that will check the values in labels 1 - 11 and if the value is less than the value in 'Total' by 2 change the label colour to red.
So if label named 'total' was 100 and labels 2 & 4 had a value of 98 or less the fore colour of labels 2 & 4 would change red.
Is this achievable? I would like to fire this in the form load event really.
Loading
VulpesPosted Apr 9, 2014, 3:47 PM
private void Form1_Load(object sender, EventArgs e)
{
// get value of 'total' label
int t = int.Parse(total.Text);
// iterate through all labels and if value <= t - 2 change forecolor to red
foreach(Control c in this.Controls)
{
if (c is Label)
{
int value;
bool isValid = int.TryParse(c.Text, out value);
if (isValid && value <= t- 2) c.ForeColor = Color.Red;
}
}
}
mike DelvottiPosted Apr 9, 2014, 4:55 PM
VulpesPosted Apr 9, 2014, 4:50 PM
mike DelvottiPosted Apr 9, 2014, 4:32 PM
Just a cheeky question, is it possible to do exactly the same but by using -2% of total label?
( I have another form that I wish to colour the label on a percentage)