System.Windows.Forms.Menu.MenuItemCollection.Find C# (CSharp) Method

Find() public method

public Find ( string key, bool searchAllChildren ) : System.Windows.Forms.MenuItem[]
key string
searchAllChildren bool
return System.Windows.Forms.MenuItem[]
			public MenuItem[] Find (string key, bool searchAllChildren)
			{
				if (string.IsNullOrEmpty (key))
					throw new ArgumentNullException ("key");
					
				List<MenuItem> list = new List<MenuItem> ();
				
				foreach (MenuItem m in items)
					if (string.Compare (m.Name, key, true) == 0)
						list.Add (m);
				
				if (searchAllChildren)
					foreach (MenuItem m in items)
						list.AddRange (m.MenuItems.Find (key, true));
						
				return list.ToArray ();
			}

Usage Example

Example #1
0
        public void MenuItemCollection_Find_NullOrEmptyKey_ThrowsArgumentNullException(string key)
        {
            var menu       = new SubMenu(new MenuItem[0]);
            var collection = new Menu.MenuItemCollection(menu);

            Assert.Throws <ArgumentNullException>("key", () => collection.Find(key, searchAllChildren: false));
        }
All Usage Examples Of System.Windows.Forms.Menu.MenuItemCollection::Find