How to use imageList Control

妖精的绣舞 提交于 2019-12-18 03:38:11

问题


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


回答1:


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"];



回答2:


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




回答3:


i am using imagelist in list view.

let say i have three images in imagelist and want to delete 2 image in it.

i used code

    imagelist.Images.RemoveAt(2);

code is deleting 2nd image but after that 3 image is bot visible although it is there



来源:https://stackoverflow.com/questions/8587269/how-to-use-imagelist-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!