Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 493683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:25:44+00:00 2026-05-13T05:25:44+00:00

I have a main form (frmMain) , with some buttons (button1, button2…) . then

  • 0

I have a main form (frmMain), with some buttons (button1, button2...).

then I do this:

object objectsContainer = frmMain; // <--now the object contains form base, button1, button2...

how could I loop through all containing items in my object to access butto1, button2…???

I did this, but it’s not what I want.

foreach (PropertyInfo pInfo in objectsContainer.GetType().GetProperties())     
{
               
}

I want to do something like this:

foreach (object objectFromForm in objectsContainer)     // <--- how to do this looping an object (type of form)
{
    //here is objectFromForm = base, button1, button2...
    foreach (PropertyInfo pInfo in objectFromForm .GetType().GetProperties())     
    {
               //here it's possible to access pInfo and its properties like size, name ...
    }
}

When I’m debuggin and looking at the content of objectsContainer there are all "infos" that I want.

Some suggestions??

Best regards.

**

UPDATE:

**

OK, I made a test project. There you could see what I want to do. In the project is an image with the objects…
Here you can download it:
http://www.mediafire.com/download.php?ik5j3ejnzm2

Best regards.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T05:25:44+00:00Added an answer on May 13, 2026 at 5:25 am

    Each Control has a Controls collection that you can iterate through to get the full hierarchy, but unfortunately ToolStrip items use a different object model (they aren’t all Controls); as such, you can iterate such a setup (to include the menu items too), but it isn’t trivial; here’s an example:

        IEnumerable RecurseObjects(object root) {
            Queue items = new Queue();
            items.Enqueue(root);
            while (items.Count > 0) {
                object obj = items.Dequeue();
                yield return obj;
                Control control = obj as Control;
                if (control != null) {
                    // regular controls and sub-controls
                    foreach (Control item in control.Controls) {
                        items.Enqueue(item);
                    }
                    // top-level menu items
                    ToolStrip ts = control as ToolStrip;
                    if (ts != null) {
                        foreach(ToolStripItem tsi in ts.Items) {
                            items.Enqueue(tsi);
                        }
                    }
                }
                // child menus
                ToolStripDropDownItem tsddi = obj as ToolStripDropDownItem;
                if (tsddi != null && tsddi.HasDropDownItems) {
                    foreach (ToolStripItem item in tsddi.DropDownItems) {
                        items.Enqueue(item);
                    }
                }
            }            
        }
    

    You might call this, for example, via something like:

        foreach (object obj in RecurseObjects(this)) {
            Console.WriteLine(obj);
        }
    

    Of course, then the question is: what do you want to do with each item?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hope I can explain this clearly enough. I have my main form (A)
I have main form and some other forms, that can be shown by controls,
I have a main form that contains two other child subforms. When a textbox
I have a main form called mainForm - this runs my entire app. In
I have a main form that is launched and then it can go to
I have a main form, which is invisible and at some point creates a
I try to achieve this: i have the main form, when user click the
This is more of an approach issue than how-to. I have a main form/document
lets say i have a main form which have a lot of functionallity. this
I have a main form and as sub form. I need the main Form

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.