Hey,


I created a form with many controls. It's a GUI for a measurement program. Therefore some controls must be disabled and some enabled.
When the START button is pressed, every control should be disabled except the ABORT button.
It works with following code:

// Disable each control in the active form's control collection except the ABORT BUTTON 
               
 for (int i = 0; i < this.Controls.Count; i++)
 {
     this.Controls[i].Enabled = false;
 }
 buttonAbort.Enabled = true;

Well, here's my problem:

AFTER the measurement is done or else the ABORT button is pressed, I want the initial state back.

How can I do this devoid of enable or disable every control on that form?

Thanks for your help.

Probably the easiest way is to include a boolean field with your objects 'previous state' and set and retrieve previous states from it.

Hello.
How about using something like:

this.Controls[i].Enabled = !this.Controls[i].Enabled;

To change the state in both ways.

I think you didn't really understand what I meant.
At the beginning, there is not every control enabled. After the measurement is done, I need exactly this state again.

Now I want to know how I can do this without saying for every button, if it's enabled or not.

I tried it with the suggestion of gerard4143.
I created a boolean array and filled it with the status if a control is enabled or not.

Thanks a lot.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.