Пример #1
0
        public void ToolboxItemCollection_CopyTo_Invoke_Success()
        {
            var item       = new ToolboxItem();
            var collection = new ToolboxItemCollection(new ToolboxItem[] { item });

            var array = new ToolboxItem[3];

            collection.CopyTo(array, 1);
            Assert.Equal(new ToolboxItem[] { null, item, null }, array);
        }
Пример #2
0
        static void Main(string[] args)
        {
            //<Snippet1>
            // Create a new ToolboxItemCollection using a ToolboxItem array.
            ToolboxItemCollection collection =
                new ToolboxItemCollection(new ToolboxItem[] {
                new ToolboxItem(typeof(System.Windows.Forms.Label)),
                new ToolboxItem(typeof(System.Windows.Forms.TextBox))
            });
            //</Snippet1>

            //<Snippet2>
            // Create a new ToolboxItemCollection using an existing ToolboxItemCollection.
            ToolboxItemCollection coll =
                new ToolboxItemCollection(collection);
            //</Snippet2>

            //<Snippet3>
            // Get the number of items in the collection.
            int collectionLength = collection.Count;
            //</Snippet3>

            //<Snippet4>
            // Get the ToolboxItem at each index.
            ToolboxItem item = null;

            for (int index = 0; index < collection.Count; index++)
            {
                item = collection[index];
            }
            //</Snippet4>

            //<Snippet5>
            // If the collection contains the specified ToolboxItem,
            // retrieve the collection index of the specified item.
            int indx = -1;

            if (collection.Contains(item))
            {
                indx = collection.IndexOf(item);
            }
            //</Snippet5>

            //<Snippet6>
            // Copy the ToolboxItemCollection to the specified array.
            ToolboxItem[] items = new ToolboxItem[collection.Count];
            collection.CopyTo(items, 0);
            //</Snippet6>
        }
Пример #3
0
        public void ToolboxItemCollection_Creation()
        {
            ToolboxItem item1 = new ToolboxItem(typeof(Bitmap));
            ToolboxItem item2 = new ToolboxItem(typeof(string));

            ToolboxItem[]         tools     = { item1, item2 };
            ToolboxItemCollection underTest = new ToolboxItemCollection(tools);

            Assert.True(underTest.Contains(item1));
            Assert.Equal(item1, underTest[0]);
            Assert.Equal(1, underTest.IndexOf(item2));

            ToolboxItem[] tools2 = new ToolboxItem[2];
            underTest.CopyTo(tools2, 0);
            Assert.Equal(item1, tools[0]);
            Assert.Equal(item2, tools[1]);
        }