예제 #1
0
        public void ToolboxItemCollection_Contains_NoSuchValue_ReturnsFalse()
        {
            var item       = new ToolboxItem();
            var collection = new ToolboxItemCollection(new ToolboxItem[] { item });

            Assert.False(collection.Contains(new ToolboxItem {
                DisplayName = "Other"
            }));
            Assert.False(collection.Contains(null));
        }
예제 #2
0
        public void ToolboxItemCollection_Ctor_ToolboxItemArray()
        {
            var item       = new ToolboxItem();
            var collection = new ToolboxItemCollection(new ToolboxItem[] { item });

            Assert.Same(item, Assert.Single(collection));
            Assert.Same(item, collection[0]);
            Assert.True(collection.Contains(item));
            Assert.Equal(0, collection.IndexOf(item));
        }
예제 #3
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>
        }
예제 #4
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]);
        }