C# 如何将图像从图像列表添加到图片框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12044877/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to add image to picturebox from imagelist
提问by diego
Hi I have an Imagelist and a picture box. I want to add the image to my picture box.
嗨,我有一个图像列表和一个图片框。我想将图像添加到我的图片框中。
I tried like this
我试过这样
picbox.Image = imagelst.Images[0];
but it didn't work.
Visual Studio does not let me to write images after imagelist
但它没有用。
Visual Studio 不允许我在 imagelist 之后写图像
回答by Hassan Boutougha
It works, I think you don't have set an image in imagelist.
它有效,我认为您没有在图像列表中设置图像。
- I set an image in imagelist.
I set this code.
namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { pictureBox1.Image = imageList1.Images[0]; } } }It works.
- 我在图像列表中设置了一个图像。
我设置了这个代码。
namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { pictureBox1.Image = imageList1.Images[0]; } } }有用。


回答by Louis van Tonder
This is an old question, but from the OP's comments, I think he does not have a instantiated imagelist object.
这是一个老问题,但从 OP 的评论来看,我认为他没有实例化的图像列表对象。
Drag an imagelist control onto the form, that will be "imagelist1" by default. You can rename it to what you want and then use it.
将一个 imagelist 控件拖到窗体上,默认为“imagelist1”。您可以将其重命名为您想要的名称,然后使用它。

