This is a migrated thread and some comments may be shown as answers.

Can't get controllers place inside the panel in c# form

1 Answer 418 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Ravindra
Top achievements
Rank 1
Ravindra asked on 27 Jun 2014, 11:25 AM
Hi..
this is the code i use for get all controllers of my form.
foreach (Control c in this.Controls)
            {
                ComponentResourceManager resources = new ComponentResourceManager(typeof(Form1));
                resources.ApplyResources(c, c.Name, new CultureInfo(lang));
            }

but ,it only get panel. how i fix this...

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 30 Jun 2014, 10:28 AM
Hello Ravindra,

Thank you for writing.

Perhaps on the top level (in the form) you just have a panel, hence the observed behavior. Each control has its own Controls collection, so in order to iterate all controls, you need to iterate all Control's collections recursively:
protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
    InitializeComponent();
 
    IterateControls(this.Controls);
 
}
 
void IterateControls(System.Windows.Forms.Control.ControlCollection collection)
{
    foreach (Control ctrl in collection)
    {
        Console.WriteLine(ctrl);
        //do smth with ctrl
        IterateControls(ctrl.Controls);
    }
}

I hope this helps.

Regards,
Stefan
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
Treeview
Asked by
Ravindra
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or