2
Answers

c#

ilhami caliskan

ilhami caliskan

10y
1.2k
1
Hi All,
 
is there a better way to do this?
 
private void handleA100ModelUpdate()
{
if (_a100SafetyModel.A100SafetyStatus[0] == true)
{
this.customTxtBox1.IoList[0].BackColor = Color.FromA#c0ffc0;
}
else
this.customTxtBox1.IoList[0].BackColor = Color.White;
if (_a100SafetyModel.A100SafetyStatus[1] == true)
{
this.customTxtBox1.IoList[1].BackColor = Color.FromA#c0ffc0;
}
else
this.customTxtBox1.IoList[1].BackColor = Color.White;
if (_a100SafetyModel.A100SafetyStatus[2] == true)
{
this.customTxtBox1.IoList[2].BackColor = Color.FromA#c0ffc0;
}
else
this.customTxtBox1.IoList[2].BackColor = Color.White;
if (_a100SafetyModel.A100SafetyStatus[3] == true)
{
this.customTxtBox1.IoList[3].BackColor = Color.FromA#c0ffc0;
}
else
this.customTxtBox1.IoList[3].BackColor = Color.White;
if (_a100SafetyModel.A100SafetyStatus[4] == true)
{
this.customTxtBox1.IoList[4].BackColor = Color.FromA#c0ffc0;
}
else
this.customTxtBox1.IoList[4].BackColor = Color.White;
if (_a100SafetyModel.A100SafetyStatus[5] == true)
{
this.customTxtBox1.IoList[5].BackColor = Color.FromA#c0ffc0;
}
else
this.customTxtBox1.IoList[5].BackColor = Color.White;
if (_a100SafetyModel.A100SafetyStatus[6] == true)
{
this.customTxtBox1.IoList[6].BackColor = Color.FromA#c0ffc0;
}
else
this.customTxtBox1.IoList[6].BackColor = Color.White;
if (_a100SafetyModel.A100SafetyStatus[7] == true)
{
this.customTxtBox1.IoList[7].BackColor = Color.FromA#c0ffc0;
}
else
this.customTxtBox1.IoList[7].BackColor = Color.White;
}
 
thanx a lot 
Answers (2)
1
Vulpes

Vulpes

NA 96k 2.6m 10y
How about:

private void handleA100ModelUpdate()
{
   for(int i = 0; i < 8; i++)
   {
     if (_a100SafetyModel.A100SafetyStatus[i])
     {
       this.customTxtBox1.IoList[i].BackColor = Color.FromArgb(0xc0ffc0);
     }
     else
       this.customTxtBox1.IoList[i].BackColor = Color.White;
   }
}

I'm guessing what Color.FromA#c0ffc0 should mean but, whatever it is, it's the same for them all.

Accepted
0
ilhami caliskan

ilhami caliskan

NA 76 93.3k 10y
:) thanx
so easy...