Click here to Skip to main content
15,867,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Colleagues,

I'm just leaning C# and I want to change a button color / label if the text.box show different values, for example the text box is a counter from 0 to 60 seconds send by an external controller (tester), so it can sometimes stops before reach 60 seconds.
my plan is to disable and write a "In cycle" in the button label/color every time the test is >0. in other words if i have "0" coming from my external controller "mw64" i want to write test in stand by in the button label.

Thank you very much in advanced.

What I have tried:

Here is what I'm using to get a variable status from a external controller.
"mw64" is a variable address that send me the actual timer 0 to 60.

the variable is being write correctly, so my outside timer is working well.
actvalueL1.Text = controller.Read("mw64").ToString();



btn_test.Text = ("Test in Stand by");
Posted
Updated 26-May-20 13:45pm

C#
int timerValue = controller.Read("mw64");
if (timerValue > 0)
    actvalueL1.Text = timerValue.ToString();
else
    actvalueL1.Text = "Test in Stand by";
 
Share this answer
 
Comments
ncostasilva 26-May-20 19:45pm    
Hello Richard MacCutchan,

Thank you for your help, i got it running well now, i have used your suggested code and it helped me to figure out a solution with some little changes.
i appreciated your help.. please see the actual solution below.
Richard MacCutchan 27-May-20 4:22am    
Glad you got it working, but as Maciej asks, why have you created two separate tests? All you need is one if statement for setting the text and colour.
if (timerValue > 0)
{
    leakstartbtn.Text = "Test is Running";
    leakstartbtn.BackColor = Color.LightSkyBlue;
}
else
{
    leakstartbtn.Text = "Start Test";
    leakstartbtn.BackColor = Color.LightGray;}
}
Maciej Los 27-May-20 3:15am    
5ed!
ncostasilva 27-May-20 18:34pm    
Hello,

perfect it was my fault, I was running into some issues with a singe statement but i found out my software was wrong, not working just fine.

Thanks again.
p_test_timer.Text = controller.Read("mw40").ToString();

        ///write test status into the start button
        int test = int.Parse(p_test_timer.Text);
        int timerValue = test;

        if (timerValue > 0)
            leakstartbtn.Text = "Test is Running";
        else
            leakstartbtn.Text = "Start Test";

        if (timerValue > 0)
            leakstartbtn.BackColor = Color.LightSkyBlue;
        else
            leakstartbtn.BackColor = Color.LightGray;
 
Share this answer
 
Comments
Maciej Los 27-May-20 2:22am    
Two times if statement? What's for?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900