创建自定义用户控制项

时间:2014-05-04 11:39:44

标签: c# winforms drop-down-menu user-controls items

我想制作带有视觉Items的自己的DropDown(Combobox),其中包含PictureNameComment。问题是如果我在属性中添加Item一切正常,Visual studio会在表单设计器中添加代码,但项目不会显示。

项目集合类:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Collections;

namespace List_Item_Test
     {
       public partial class My_Item : CollectionBase
        {
        public Items this[int Index]
        {
            get
            {
                return (Items)List[Index];
            }
        }

        public bool Contains(Items itemType)
        {
            return List.Contains(itemType);
        }

        public int Add(Items itemType)
        {
        //i think hier something is missing???
            return List.Add(itemType);
        }

    public void Remove(Items itemType)
    {
        List.Remove(itemType);
    }

public void Insert(int index, Items itemType)
    {
        List.Insert(index, itemType);
    }

        public int IndexOf(Items itemType)
        {
            return List.IndexOf(itemType);
        }

    }
}

项目容器类:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace List_Item_Test
{
    public partial class Item_Container : UserControl
    {
        public Item_Container()
        {
            InitializeComponent();
        }

        My_Item hallo = new My_Item();

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public My_Item MyItemTypes
        {
            get { return hallo; }
            set
            {
                Items hallo1 = new Items();
                hallo1.SetBounds(0, 10 + /*hallo.Count - 1 **/ 50, Width, 50);
                this.Controls.Add(hallo1);
            }
        }
    }
}

0 个答案:

没有答案