Click here to Skip to main content
11,641,067 members (62,772 online)
Rate this: bad
good
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 at 12-Apr-11 18:26pm
   
Nice and simple - good answer :)
Nishant Sivakumar at 12-Apr-11 18:28pm
   
Thank you Espen!
SAKryukov at 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 at 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 at 8-Apr-14 12:27pm
   
3 years late!
CHill60 at 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 at 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 at 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
0 Mika Wendelius 400
1 OriginalGriff 205
2 DamithSL 203
3 CPallini 145
4 Afzaal Ahmad Zeeshan 129
0 Mika Wendelius 380
1 OriginalGriff 205
2 DamithSL 203
3 CPallini 125
4 Afzaal Ahmad Zeeshan 89


Advertise | Privacy | Mobile
Web03 | 2.8.150731.1 | Last Updated 8 Apr 2014
Copyright © CodeProject, 1999-2015
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