如何将类似ListBox属性的项添加到自定义控件? [英] How to add Items like attribute of ListBox to a custom control?

查看:132
本文介绍了如何将类似ListBox属性的项添加到自定义控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将自定义属性添加到自定义按钮控件,如ListBox Control的Items属性,以便用户可以使用设计器编辑器将项添加到自定义按钮控件。

I want to add a custom attribute to a custom button control like Items attribute of ListBox Control so that user can add item to custom button control using designer editor.

public List<string> LstOfValues = new List<string>();

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public List<string> Items
        {
            get { return LstOfValues; }
            set {
                LstOfValues.Clear();
                foreach (string s in value)
                {
                    LstOfValues.Add(s);
                }
            }
        }





i已将上面的代码添加到我的自定义按钮控件和属性命名项目添加到属性窗口但是当我想使用设计编辑器添加任何项目时,我得到一个错误,说未找到类型''System.String'上的构造函数。



提前感谢



i have added above code to my custom button control and an attribute named Items added to property window but when i want to add any item to this using design editor i have got an error saying "Constructor on type ''System.String'' not found".

thanks in advance

推荐答案

这是自定义UITypeEditor [ ^ ]。有关为自定义对象构建编辑器的示例,请参阅该链接,该编辑器适用于.NET的PropertyEditor。
That''s a job for a custom UITypeEditor[^]. See the link for an example on building an editor for your custom object that works with .NET''s PropertyEditor.


这篇关于如何将类似ListBox属性的项添加到自定义控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆