Enumerate .Net control's items generically (MenuStrip, ToolStrip, StatusStrip)

后端 未结 3 1964
北恋
北恋 2020-12-17 06:40

I\'ve got some code that will generically get all Controls in a form and put them in a list. Here\'s some of the code:

        private List Ge         


        
3条回答
  •  执笔经年
    2020-12-17 07:33

    ToolStripControlHost might contain a Control:

    if (c is ToolStrip)
        foreach (ToolStripItem item in EnumerateTree(c, "Items"))
            if (item is ToolStripControlHost)
                AddControlsToList(
                    new Control[] { ((ToolStripControlHost)item).Control },
                    controlList);
    

    ...that's if you change argument 1 to type IEnumerable and write your own EnumerateTree function (I think it's great to have one good generic EnumerateTree method).

提交回复
热议问题