You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 04:34:54