Hi. I'm trying to build a UI which makes use of about 18 buttons to fulfil certain tasks. The problem is if a button has been pressed before the previous command has finished executing it can cause problems. To solve the issue i'm blocking all the buttons while the command is executed. However, because in some cases the command needs to be turned off manually, that specific button cannot be disabled.
For example: I have to press button1 to turn on the motor and press it again to turn it off. While the motor is running all other buttons should be disabled.
My question is: Is there a more efficient way of disabling all buttons except the active one, rather than conditionally enabling/disabling each one? Thank you in advance. I am currently using this code:
private
void button_toggle()
{
btn_Finished.Enabled = !toggle;
btn_Do_Empty.Enabled = !toggle;
btn_Do_Fill_toSensor.Enabled = !toggle;
btn_Purge_Fill.Enabled = !toggle;
btn_Fill_Dome.Enabled = !toggle;
btn_Pulse_Reagent.Enabled = !toggle;
btn_Pulse_Standard.Enabled = !toggle;
toggle = !toggle;
}
Sam HobbsPosted Sep 7, 2013, 1:05 AM
You could make an array of buttons; just the ones that need to be enabled or disabled all at once. I think that would satisfy the requirements you have provided but I suspect that your requirements are more complex than stated here. If relevant, you could have separate arrays and the use of each array depends on the state of the machinery.
You could put buttons in a container of some type as children of the container then you could just enable and disable the container. One possibility might be a tab control but there are others.
If none of those satisfy your requirements then please clarify your requirements.
Javeed M ShaikhPosted Sep 6, 2013, 11:12 AM
you can call them like this:
This code is not tested, so please test/debug/fix accordingly.
Stefan CazacuPosted Sep 6, 2013, 10:39 AM
I thought about this approach, however I have a large number of buttons and was hoping for a shorter, if not simpler, way of coding this functionality for all of them
Kiran Kumar TalikotiPosted Sep 6, 2013, 10:00 AM
If u want to Disable the buttons(by clicking another button)...
Suppose there are two Button1 and Button2 button:
If you Click On button1:
Button Button1=new Button();
Button Button2=new Button();
//Button1 click event
private Button1_Cilck()
{
//Conditition for on
button2.IsEnabled=false;
}
If you Click On button2:
//Button2 click event
private Button2_Click()
{
//Conditition for on
button1.IsEnabled=false;
}