如何将imageList中的图片传入DevExpress的imageListBoxControl组件?
如何将ImageList中的图片导入DevExpress的ImageListBoxControl?
你的代码存在逻辑错误:循环里试图把单个Image对象赋值给imageListBoxControl1.ImageList,但这个属性需要的是完整的ImageList控件实例,而非单张图片。正确的做法是先关联整个ImageList,再为每张图片添加对应的列表项:
private void AddAutomobileForm_Load(object sender, System.EventArgs e) { // 关联ImageList控件,让ImageListBoxControl知道图片来源 imageListBoxControl1.ImageList = imageList1; // 遍历ImageList中的所有图片,为每张图添加列表项 for (int i = 0; i < imageList1.Images.Count; i++) { // 创建带图片的列表项:第一个参数是项的自定义数据,第二个是显示文本,第三个是图片索引 imageListBoxControl1.Items.Add(new DevExpress.XtraEditors.Controls.ImageListBoxItem(null, $"图片 {i+1}", i)); } }
关键说明:
- 直接设置
ImageList属性即可绑定整个图片集合,无需循环赋值单张图。 ImageListBoxItem的第三个参数对应imageList1中图片的索引,确保列表项能正确显示对应图片。- 你可以修改第二个参数(显示文本),比如替换成图片的实际文件名或自定义描述。
内容的提问来源于stack exchange,提问作者Behfar Baghovvat
相关产品推荐
相关产品推荐

