Dev 控件imageComboBoxEdit 添加图片

本文详细介绍如何使用ImageComboBoxEdit控件与ImageCollection组件来创建带图标的下拉列表,包括配置步骤及代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

先上图,后说明。

                    图1

图1便是想要达到的效果。

1、先添加ImageComboBoxEdit控件,我将name改为imageComboBoxSplit,为了和后续代码相吻合。

2、添加ImageCollection控件。name设为imageCollection。

3、看图2,进入ImageCollection任务(鼠标点击ImageCollection上的小三角),点击EditImageCollect。

                                              图2

4、看图3,点击添加按钮找到你想试用的图片,确定即可。


                                                                                                 图3

5、进入ImageComboBoxEdit任务,选中Small Images下拉列表中的imageCollection(图4),然后点击下面的Edit items,进入图5。


                                                              图4

6、然后,添加成员,对右侧的三个杂项进行更改,其中ImageIndex改为你想要的图片的index。


图5

设计生成的部分代码如下:

-----------------------------------------------------------------代码分隔线----------------------------------------------------------------------------------------

// 
            // imageComboBoxSplit
            // 
            this.imageComboBoxSplit.Location = new System.Drawing.Point(5, 3);
            this.imageComboBoxSplit.Name = "imageComboBoxSplit";
            this.imageComboBoxSplit.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
            new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)});
            this.imageComboBoxSplit.Properties.Items.AddRange(new DevExpress.XtraEditors.Controls.ImageComboBoxItem[] {
            new DevExpress.XtraEditors.Controls.ImageComboBoxItem("一分屏幕", "1", 0),
            new DevExpress.XtraEditors.Controls.ImageComboBoxItem("四分屏幕", "4", 2),
            new DevExpress.XtraEditors.Controls.ImageComboBoxItem("九分屏幕", "9", 5),
            new DevExpress.XtraEditors.Controls.ImageComboBoxItem("十六分屏幕", "16", 6)});
            this.imageComboBoxSplit.Properties.SmallImages = this.imageCollection;
            this.imageComboBoxSplit.Size = new System.Drawing.Size(100, 20);
            this.imageComboBoxSplit.TabIndex = 0;
            this.imageComboBoxSplit.SelectedIndexChanged += new System.EventHandler(this.imageComboBoxSplit_SelectedIndexChanged);
            // 
            // imageCollection
            // 
            this.imageCollection.ImageStream = ((DevExpress.Utils.ImageCollectionStreamer)(resources.GetObject("imageCollection.ImageStream")));
            this.imageCollection.Images.SetKeyName(0, "dlg_pane_view_light_1.jpg");
            this.imageCollection.Images.SetKeyName(1, "dlg_pane_view_light_2.jpg");
            this.imageCollection.Images.SetKeyName(2, "dlg_pane_view_light_4.jpg");
            this.imageCollection.Images.SetKeyName(3, "dlg_pane_view_light_6.jpg");
            this.imageCollection.Images.SetKeyName(4, "dlg_pane_view_light_8.jpg");
            this.imageCollection.Images.SetKeyName(5, "dlg_pane_view_light_9.jpg");
            this.imageCollection.Images.SetKeyName(6, "dlg_pane_view_light_16.jpg");
            this.imageCollection.Images.SetKeyName(7, "dlg_pane_view_light_36.jpg");
            this.imageCollection.Images.SetKeyName(8, "dlg_pane_view_light_64.jpg");


这篇文章中我们重点需要实现的是(3)、(4)两项功能,下面我们来介绍具体实现的方法。 第一步,实现ImageComboBoxItem类。 要实现显示图标,当然要给每个项添加与图标相关的信息了,ImageComboBoxItem类应该包括以下内容:文本(Text)、缩进的级别(Level)、图标的索引(ImageIndex、ImageKey),用户数据(Tag)。ImageComboBoxItem类实现了ISerializable接口,实现自定义序列化。ImageComboBoxItem类的类视图如下: 图3 ImageComboxItem类视图 ImageComboBoxItem类的代码如下: [Serializable] [DefaultProperty("Text")] [TypeConverter( typeof(ExpandableObjectConverter))] public class ImageComboBoxItem : IDisposable, ISerializable ...{ Fields#region Fields private ImageComboBox _imageComboBox; private string _text = "ImageComboBoxItem"; private ImageComboBoxItemImageIndexer _imageIndexer; private object _tag; private int _level; #endregion Constructors#region Constructors public ImageComboBoxItem() ...{ } public ImageComboBoxItem(string text) : this(text, -1, 0) ...{ } public ImageComboBoxItem( string text, int imageIndex) : this(text, imageIndex, 0) ...{ } public ImageComboBoxItem( string text, string imageKey) : this(text, imageKey, 0) ...{ } public ImageComboBoxItem( string text, int imageIndex, int level) : this() ...{ _text = text; ImageIndexer.Index = imageIndex; _level = level; } public ImageComboBoxItem( string text, string imageKey, int level) : this() ...{ _text = text; ImageIndexer.Key = imageKey; _level = level; } protected ImageComboBoxItem( SerializationInfo info, StreamingContext context) : this() ...{ Deserialize(info, context); } #endregion Properties#region Properties [Localizable(true)]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值