private MenuItemCollection Find(string name, Menu menu, Control sourceControl) { MenuItemCollection results = new MenuItemCollection(); if(Matches(name, menu, sourceControl)) { results.Add((MenuItem) menu); } foreach(MenuItem m in menu.MenuItems) { results.Add(Find(name, m, sourceControl)); } return results; }
/// <summary> /// Finds the MenuItem. /// </summary> /// <returns>the MenuItem found by this MenuItemFinder.</returns> /// <exception cref="NoSuchControlException"> /// Thrown if this MenuItem is not found.</exception> /// <exception cref="AmbiguousNameException"> /// Thrown if multiple MenuItems are found with the same name.</exception> public MenuItem Find() { MenuItemCollection found = new MenuItemCollection(); foreach(Form form in FormCollection) { if(form.Menu != null) { found.Add(Find(name, form.Menu, form)); } found.Add(Find(name, form)); } if(found.Count == 1) { return found[0]; } else if(found.Count == 0) { throw new NoSuchControlException(name); } else { throw new AmbiguousNameException(name); } }
private MenuItemCollection Find(string name, Control control) { MenuItemCollection results = new MenuItemCollection(); foreach(Control c in control.Controls) { results.Add(Find(name, c)); if(c.ContextMenu != null) { results.Add(Find(name, c.ContextMenu, c)); } } return results; }