Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
333 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...