Click here to Skip to main content
15,895,833 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

Can you provide a function which disables/enables all controls in a c#.net Windows Form

Please help!!!
Posted

Answered here:

http://stackoverflow.com/questions/1676766/getting-controls-in-a-winform-to-disable-them[^]

See the top rated answer from Ed S:

C#
// This code snippet is from the SO thread linked above (by Ed S)
void ChangeEnabled( bool enabled ) 
{ 
    foreach ( Control c in this.Controls ) 
    { 
        c.Enabled = enabled;     
    } 
} 
 
Share this answer
 
v3
Comments
Espen Harlinn 12-Apr-11 18:26pm    
Nice and simple - good answer :)
Nish Nishant 12-Apr-11 18:28pm    
Thank you Espen!
Sergey Alexandrovich Kryukov 12-Apr-11 18:34pm    
That's correct, my 5.
This is funny: I almost thought about writing recursive variant. :-)
In fact, it would be redundant: changing Enabled for any parent control automatically renders all the children enabled or disabled.
--SA
Nish Nishant 12-Apr-11 18:36pm    
Thanks SA.
I use queue and recursive function to get all controls.

my solution is here : http://stackoverflow.com/a/22940027/929740[^]
 
Share this answer
 
Comments
CHill60 8-Apr-14 12:27pm    
3 years late!
CHill60 8-Apr-14 12:39pm    
See the comment from SAKryukov to solution 1 on 12-Apr-11 ... "changing Enabled for any parent control automatically renders all the children enabled or disabled"
Add all controls to a panel and disable/enable panel.
 
Share this answer
 
Comments
CHill60 8-Apr-14 16:34pm    
Question was answered 3 years ago. Watch out for members reincarnating old posts - they reappear in the "All Questions" list - even if the latest post gets deleted
saber rezaii magham 8-Apr-14 16:40pm    
Yes I know,but this is a very Easier way.

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