I want to find all controls in my form that implement a certain interface (let's say ITestInterface
). I have tried this:
this.Controls.OfType<ITestInterface>();
but it goe's only one level deep (despite what is written in MSDN - @dasblinkenlight), so if for example, I have a panel in the form and an ITestInterface
control inside the panel, it will not find it.
How to do that?
Edit: As @HansPassant wrote in a comment, I could hard-code my panels name, however, I need a general solution, and not a specific solution to a particular form.