FindControl() Windows Forms Equivalent??

Hi all,

I would like to be able to search adn retrieve all the Controls (or types of Controls) that are based on my Windows Form. Is there a function that does this I know in ASP.NET you have the FindControl() method, and was wondering if there was something similar

Thanks

Tryst



Answer this question

FindControl() Windows Forms Equivalent??

  • Daniel Glastonbury

    Hi Tryst,

    I appreciate your prompt response. : )

    If you have any other concern, please feel free to post back. I am always very happy to be of assistance.

    Have a nice day!

    Best regards,
    Peter Huang



  • Jesse McGatha

    Hi,

    Based on my understanding, you want to know if there is a method similar with FindControl in Winform just as ASP.NET does.

    If I misunderstood, please feel free let me know.

    I think we can use the Find method of Controls collection.
    e.g.
    {
    Control[] ctls = this.Controls.Find("Button2", true);
    if (ctls.Length > 0)
    {
    Button btn = ctls[0] as Button;
    if (btn != null)
    btn.PerformClick();
    }
    else
    MessageBox.Show("Not Found");
    }

    private void button2_Click(object sender, EventArgs e)
    {
    MessageBox.Show("Button2 Clicked");
    }

    If you still have any concern, please feel free to post here.

    Best regards,
    Peter Huang



  • DM_01

    Yes, that would be it! Thanks :)

    In ASP.NET the FindControl() method is a property of the Page class, where as it seems here that the Find() method must be called from the Controls collection.

    Thanks for your help.

    Tryst


  • FindControl() Windows Forms Equivalent??