Question : How to make all the controls readonly at runtime in c# windows form

How to make all the controls readonly at runtime in c# windows form
i have some 20 controls on a form if user clicks button i want to show all the controls as readonly instead of making each control readonly is their a way to make all the controls as readonly at once  
thanks

Answer : How to make all the controls readonly at runtime in c# windows form

foreach (Control ctrl in this.Controls)
            {
                if (ctrl.GetType() == typeof(Panel))
                {
                    if (ctrl.GetType() == typeof(UserDefinedTextBox))
                    {
                        UserDefinedTextBox  tb = ctrl as UserDefinedTextBox;
                        tb.ReadOnly = true;
                    }
                }
            }
if you want to get at the controls on the panel you have to iterate through them
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
foreach (Control ctrl in this.Controls)
            {
                if (ctrl.GetType() == typeof(Panel))
                {
                    foreach(Control panelControl in ctrl.Controls)
                    {
                    if (ctrl.GetType() == typeof(UserDefinedTextBox))
                    {
                        UserDefinedTextBox  tb = ctrl as UserDefinedTextBox;
                        tb.ReadOnly = true;
                    }
                    }
                }
            }
Random Solutions  
  •  How do you import outlook express 6 messages into Windows Live Mail and have them in the proper folders?
  •  Cannot use remote executables after I upgraded to R2
  •  Mixed tooltips using AddTool (GetDlgItem (IDC_THIS), IDC_THIS) and AddTool (this, LPSTR_TEXTCALLBACK) how to.
  •  VPN client (Check point Secure client) not able to browse to any website on the machine once connected to the VPN.
  •  How do I remove special characters in a query?
  •  Reading XML in to an ADO Recordset
  •  msaccess 2003 and turning on a new menu toolbar from module code and turning off the main menu from the same place
  •  Problem with Joomla email cloaking
  •  can i use right([ClientName] to get the last part of a string in a Microsoft Access query if i don't know how long the last part is?
  •  How can I print using a Clipper (DOS) application under Windows 7
  •  
    programming4us programming4us