none
开发用户控件中,如何定制集合属性编辑器? RRS feed

  • 问题

  •         public struct MenuItem_Struct
            {
                public string menu;
                public string item;
            }
    
            MenuItem_Struct[] MenuItem;
    
            public MenuItem_Struct[] ss
            {
                set
                {
                    MenuItem = value;
                }
                get
                {
                    return MenuItem;
                }
            }
    
    

    这个是控件中的一个属性,打开该属性编辑器后值无法设置,

    该如何操作呢?

    2014年10月27日 10:35

答案

全部回复

  • 你好:

    需要对集合中的类型做序列化,参考一下这个代码:

    public partial class MyUserControl : UserControl
        {
            public MyUserControl()
            {
                InitializeComponent();
                if (ss == null)
                {
                    ss = new Collection<MenuItem_Struct>();
                }
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                textBox1.Text = "Hello World";
            }
    
    
            [Description("Test text displayed in the textbox"), Category("Data")]
            public string CustomText
            {
                get { return textBox1.Text; }
                set { textBox1.Text = value; }
            }
    
            [Description("Test text displayed in the textbox"), Category("Data")]
            public List<string> CustomList
            {
                get;
                set;
            }
    
            [Serializable]
            public struct MenuItem_Struct
            {
                public string menu{get;set;}
                public string item { get; set; }
            }
    
            [Category("Data")]
            [Description("asdf")]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            public Collection<MenuItem_Struct> ss
            {
                get;
                set;
            }
    
            protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
            {
                base.SetBoundsCore(x, y, 200, 200, specified);
            }
        }


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2014年10月28日 2:44
    版主
  • 另外我感觉你需要找一本有关用户控件开发的书或者在网络上找一些相关的资料系统的学习一下用户控件的开发。

    比如MSDN上的文章:

    http://msdn.microsoft.com/en-us/library/ms235628(v=vs.80).aspx

    http://msdn.microsoft.com/en-us/library/ms233813.aspx


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • 已标记为答案 vboykk 2014年10月28日 8:22
    2014年10月28日 2:50
    版主
  • 太感谢了!!!!
    2014年10月28日 8:22