Sunday, April 3, 2011

How deep does the Control.Contains method search?

I need to check whether a control is a descendant of another control. Will Control.Contains do the job, or does that only search for first-level child controls?

From stackoverflow
  • I just tested it, and it looks like it does indeed do a recursive search.

  • Control.Contains makes a recursive search. So it will return true for this case:

    ctrl1.Contains(ctrl3);
    

    where ctrl1 contains ctrl2, and ctrl2 contains ctrl3 (for example).

    BTW: .NET Reflector is a great tool to find out such things.

0 comments:

Post a Comment