How to get all children of a parent control?

前端 未结 4 1090
长发绾君心
长发绾君心 2020-12-03 15:03

I\'m looking for an code example how to get all children of parent control.

I have no idea how do it.

foreach (Control control in Controls)
{
  if (         


        
4条回答
  •  余生分开走
    2020-12-03 15:39

    Controls have a MyControl.Controls collection which you can do a foreach on.

    Each Control also has a Parent property which gives you the parent control.

    You can write a recursive method if you need to go down an unknown number of levels.

提交回复
热议问题