Click here to Skip to main content
12,406,795 members (55,513 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
Hi All,

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

Please help!!!
Posted 12-Apr-11 12:09pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Answered here:

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

See the top rated answer from Ed S:

// 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;     
    } 
} 
  Permalink  
v3
Comments
Espen Harlinn 12-Apr-11 18:26pm
   
Nice and simple - good answer :)
Nishant Sivakumar 12-Apr-11 18:28pm
   
Thank you Espen!
SAKryukov 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
Nishant Sivakumar 12-Apr-11 18:36pm
   
Thanks SA.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

I use queue and recursive function to get all controls.

my solution is here : http://stackoverflow.com/a/22940027/929740[^]
  Permalink  
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"
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

Add all controls to a panel and disable/enable panel.
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160730.1 | Last Updated 8 Apr 2014
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100