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 4552140
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:44:17+00:00 2026-05-21T16:44:17+00:00

I believe the proper term is recursively . I have a Windows Form, and

  • 0

I believe the proper term is recursively. I have a Windows Form, and inside that I have a Tab Control, and inside the Tab Control are four Tabs, and inside each tab are multiple controls – Buttons, text boxes, etc. I want to change the cursor of every button to a type hand.

Below is where I have gotten so far with this inquiry:

foreach (Control c in tabControl1.Controls)
         {

             // The only controls that will be found here are the tabs themselves. So, now I must run a *foreach* loop through every tab found, and look if buttons are present.

         }

The commented area explains my issue to some extent. I have found an example of a recurisively finding a control on a form but I am not sure why I would need to pass the contro’s name as an argument as I am trying to find Every control of type button.

Here is the code that I found online:
http://www.dreamincode.net/code/snippet1663.htm

Thank you once again. I love hearing from all of you as it’s an excellent learning experience for me.

Thank you very much for your time.

  • 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-21T16:44:17+00:00Added an answer on May 21, 2026 at 4:44 pm
    private void FindAll(Control myControl)
    {
        if (myControl is Button)
            doStuff();
    
        foreach (Control myChild in myControl.Controls)            
            FindAll(myChild);
    
    }
    

    I believe this will work. When you call it the first time, you’d pass in the form. The form isn’t a button, but it will have children. Each child it has will be passed into FindAll(). If that control is a button, it will call doStuff() (you can set the cursor in there). Likewise if that control has any children, they’ll be passed in.

    You are correct, the term is recurisve (generally speaking, any function or sub that calls itself). So, in this example FindAll() will call FindAll() in a certain case.

    Also, this is just sample code; you may want to check for null references depending on the nature of your application.

    EDIT: Just as an FYI if you aren’t familiar with recursion, it’s pretty easy to get the dreaded StackOverflow exception. When you end up in a never-ending loop of calling yourself, you’ll run out of stackspace and see the StackOverflow exception. Hence, the name http://www.StackOverflow.com

    In this case, we don’t have to worry because .NET prevents us from adding controls that create a circular reference. For example – this code will fail:

        GroupBox g1 = new GroupBox();
        GroupBox g2 = new GroupBox();
        GroupBox g3 = new GroupBox();
    
        g1.Controls.Add(g2);
        g2.Controls.Add(g3);
        g3.Controls.Add(g1);
    

    I don’t know if any of this makes sense, but hopefully it helps. Recursion is generally considered one of the ‘harder’ concepts to grasp for a lot of people. Then again, I’m not very good at explaining things.

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

Sidebar

Related Questions

I know that this question might have been asked like 100 times, but, believe
I have a view in iOS (iPhone) that have multiple components, organized in sort
I believe that I couldn't find a proper title to explain my problem but
I have implemented what I believe to the proper way to delete a database
I believe that the rallytagpicker is definitely a useful component. However, I do not
I believe Wordpress stores multiple entries of posts as revisions but I think thats
I believe my problem stems from my use of weights and the RelativeLayout that
I believe this question has been asked a lot of times, and I have
I believe it is a simple mistake but I have spent a lot of
I have some deep question about OOP architecture. What is a proper way to

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.