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

2 posts, 0 answers
  1. Ravindra
    Ravindra avatar
    2 posts
    Member since:
    Apr 2014

    Posted 27 Jun 2014 Link to this post

    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...
  2. Stefan
    Stefan avatar
    2908 posts

    Posted 30 Jun 2014 Link to this post

    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)
    void IterateControls(System.Windows.Forms.Control.ControlCollection collection)
        foreach (Control ctrl in collection)
            //do smth with ctrl

    I hope this helps.

    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.
Back to Top