Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use imageList Control

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

like image 645
NIlesh Lanke Avatar asked Dec 21 '11 09:12

NIlesh Lanke


People also ask

What is ImageList controls?

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.

How to use ImageList in vb net?

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.

What is an ImageList in C#?

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.

What is the purpose of the image list 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.


2 Answers

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"];
like image 98
Niranjan Singh Avatar answered Oct 18 '22 01:10

Niranjan Singh


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

like image 25
Cody Gray Avatar answered Oct 18 '22 01:10

Cody Gray