-1

I need to get any child item of ToolStrip/MenuStrip/StatusStrip for translate the texts.

I did it with Controls by simple recursion but I don't know how to do that with ToolStrip items because there is not DropDownItems property in ToolStripItem class.

user6466445
  • 11
  • 1
  • 5
  • 1
    If you want a question answered on stack. don't dump a general problem, Provide Minimal, Complete Verifiable Example, and read our posting guide lines – johnny 5 Aug 24 '16 at 14:25
  • Possible duplicate of [Enumerate .Net control's items generically (MenuStrip, ToolStrip, StatusStrip)](http://stackoverflow.com/questions/297335/enumerate-net-controls-items-generically-menustrip-toolstrip-statusstrip) – 001 Aug 24 '16 at 14:29

1 Answers1

1

I written this and it does the work well.

private ToolStripItem[] GetAllChildren(ToolStripItem item)
    {
        List<ToolStripItem> Items = new List<ToolStripItem> { item };
        if (item is ToolStripMenuItem)
            foreach (ToolStripItem i in ((ToolStripMenuItem)item).DropDownItems)
                Items.AddRange(GetAllChildren(i));
        else if (item is ToolStripSplitButton)
            foreach (ToolStripItem i in ((ToolStripSplitButton)item).DropDownItems)
                Items.AddRange(GetAllChildren(i));
        else if (item is ToolStripDropDownButton)
            foreach (ToolStripItem i in ((ToolStripDropDownButton)item).DropDownItems)
                Items.AddRange(GetAllChildren(i));
        return Items.ToArray();
    }
user6466445
  • 11
  • 1
  • 5
  • 1
    This is redundant. The common base class is [`ToolStripDropDownItem`](https://msdn.microsoft.com/en-us/library/system.windows.forms.toolstripdropdownitem(v=vs.110).aspx) and `DropDownItems` is a property of the common base class. You can remove the Type tests and use the same code to insert into the array. – Jasen Aug 24 '16 at 17:47
  • Thanks! That what I searched for:) – user6466445 Aug 24 '16 at 22:24