System.Windows.Forms.ToolStripItemCollection.Find C# (CSharp) Method

Find() private method

private Find ( string key, bool searchAllChildren ) : System.Windows.Forms.ToolStripItem[]
key string
searchAllChildren bool
return System.Windows.Forms.ToolStripItem[]
		public ToolStripItem[] Find (string key, bool searchAllChildren)
		{
			if (key == null || key.Length == 0)
				throw new ArgumentNullException ("key");

			List<ToolStripItem> list = new List<ToolStripItem> ();

			foreach (ToolStripItem tsi in this) {
				if (String.Compare (tsi.Name, key, true) == 0) {
					list.Add (tsi);

					if (searchAllChildren) {
						// TODO: tsi does not have an items property yet..
					}
				}
			}

			return list.ToArray ();
		}

Usage Example

コード例 #1
0
        static ToolStripItem Find(ToolStripItemCollection items, String key, bool searchAllChildren)
        {
            var tis = items.Find(key, searchAllChildren);
            if (tis != null && tis.Length > 0) return tis[0];

            foreach (ToolStripItem item in items)
            {
                if (item.Text.EqualIgnoreCase(key)) return item;
            }
            if (searchAllChildren)
            {
                foreach (ToolStripItem item in items)
                {
                    var tdi = item as ToolStripDropDownItem;
                    if (tdi != null)
                    {
                        var ti = Find(tdi.DropDownItems, key, searchAllChildren);
                        if (ti != null) return ti;
                    }
                }
            }

            return null;
        }