954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Enable a special button

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.

Tortura
Newbie Poster
15 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
 

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

gerard4143
Nearly a Posting Maven
2,272 posts since Jan 2008
Reputation Points: 512
Solved Threads: 387
 

Hello.
How about using something like:

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

To change the state in both ways.

Antenka
Posting Whiz
362 posts since Nov 2008
Reputation Points: 293
Solved Threads: 82
 

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.

Tortura
Newbie Poster
15 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
 

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.

Tortura
Newbie Poster
15 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: