Exemplo n.º 1
0
        ///<summary>Collect all checked items from a <see cref="System.Windows.Forms.ToolStripItemCollection"/>
        ///and into a <see cref="System.Windows.Forms.ToolStripMenuItem"/> array.</summary>
        ///<param name="items"><see cref="System.Windows.Forms.ToolStripItemCollection"/></param>
        ///<returns><see cref="System.Array"/> of <see cref="System.Windows.Forms.ToolStripMenuItem"/></returns>
        private static ToolStripItem[] Choices(ToolStripItemCollection items)
        {
            var choices = new ToolStripItem[items.Count];

            items.CopyTo(choices, 0);
            return(Array.FindAll(choices, item => item is ToolStripMenuItem && ((ToolStripMenuItem)item).Checked));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sorts the ToolStripItemCollection using the specified comparer.
        /// </summary>
        /// <param name="collection">The collection of ToolStripItems.</param>
        /// <param name="comparer">The comparer to use for sorting the ToolStripItems.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="collection"/> is null.
        /// or
        /// <paramref name="comparer"/> is null.
        /// </exception>
        public static void Sort(this ToolStripItemCollection collection, IComparer <ToolStripItem> comparer)
        {
            if (collection == null)
            {
                throw new ArgumentNullException(nameof(collection));
            }
            if (comparer == null)
            {
                throw new ArgumentNullException(nameof(comparer));
            }

            // If a ToolStripItemCollection only contains one item it does not need to be sorted.
            if (collection.Count > 1)
            {
                ToolStripItem[] items = new ToolStripItem[collection.Count];
                collection.CopyTo(items, 0);

                Array.Sort(items, comparer);

                collection.Clear();
                collection.AddRange(items);
            }
        }
Exemplo n.º 3
0
 public void CopyTo(Array array, int index)
 {
     collection.CopyTo(array, index);
 }