C# 创建自定义用户控件项
我想用可视化的C# 创建自定义用户控件项,c#,winforms,drop-down-menu,user-controls,items,C#,Winforms,Drop Down Menu,User Controls,Items,我想用可视化的项目创建自己的下拉列表(组合框),其中包含图片、名称和注释。问题是如果在属性中添加项,一切正常,VisualStudio会在表单设计器中添加代码,但该项不会显示 项目集合类: using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text;
项目创建自己的下拉列表(组合框),其中包含图片
、名称
和注释
。问题是如果在属性中添加项
,一切正常,VisualStudio会在表单设计器中添加代码,但该项不会显示
项目集合类:
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);
}
}
}
}
这些是你仅有的代码吗?将图片添加到组合框项目的代码部分在哪里?将项目添加到组合框的代码部分在哪里?(您的MyItemTypes
属性从未被调用,因此其setter代码从未运行过。)该项是我的用户控件,我想创建自己的类似组合框的组件,在其中列出这些项。(比如:)没有关系,但是你可以在家里轻松地做这种事情WPF@AshtonWoods你说的“不相关”是什么意思?我不想使用wpf有很多原因