I have some images that i added to imageList Cotrol manually. Now i need remove thart images from imageList depending on the key index and set as panel backgroud.
How should i do it
The ImageList is a control that enables you to store graphic images in an application. Other controls can then use the ImageList as a central repository for the images that they will use. Both bitmaps (*. bmp files) and icons (*. ico files) can be stored in the ImageList control.
To use the ImageList control in a project, double-click its icon in the Toolbox (you'll find it in the Components tab) to place an instance of the control on your form. To load images to an ImageList control, locate the Images property in the Properties window and click the ellipsis button next to the property name.
An ImageList is a supporting control that is typically used by other controls, such as a ListView but is exposed as a component to developers. We can use this component in our applications when we are building our own controls such as a photo gallery or an image rotator control.
The ImageList control is used to store images that are used by other Windows Forms controls. The ImageList control stores images as if they were stored on a roll of film. Unlike a roll of film, however, it's a simple matter to add images to and remove images from an ImageList control.
Images
that you added in Image list are added to the ImageList.ImageCollection, so it is collection type then you can use most of the collection methods.
Use the Images property to add, remove and access the image to display in background of panel.
Add(key,image)
Remove()
RemoveAt()
RemoveByKey()
Check the example on the ImageList Class documentation to understand that how pragmatically use all of these methods.
Add Image:
imageList1.Images.Add("pic1", Image.FromFile("c:\\mypic.jpg"));
Remove Image from collection:
imageList1.Images.RemoveAt(listBox1.SelectedIndex);
imageList1.Images..RemoveByKey("pic1");
To access images, get image from the imagecollection
panel1.BackgroundImage = imageList1.Images[0];
or
panel1.BackgroundImage = imageList1.Images["pic1"];
Use the Images
property of the ImageList
control.
The ImageList.ImageCollection
object that it returns provides all the methods you need to manipulate the images in the list, including Add
and Remove
methods.
You can find instructions on setting the background of a Panel
control here: How to: Set the Background of a Windows Forms Panel
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With