当控件在同一项目中时,如何将扩展控件添加到工具箱?
How to add an extended control to the toolbox, when the control is in the same project?
我延长了DataGridView
。我想将新控件添加到工具箱而不添加对不同程序集的引用(使用右键单击选项 "Choose Items")。控件在窗体的同一个项目中,我不想将它们分开。我怎样才能做到这一点?
谢谢。
编辑:如果它不是用户控件,则不可能重复有关用户控件的问题。
编辑 2: 代码本身(这是一个进行中的工作。尚未完成):
class BindedDataGrid<T> : DataGridView
{
public BindedDataGrid()
{
InitializeComponent();
IEnumerable<PropertyInfo> properties = typeof(T).GetProperties().Where(p => Attribute.IsDefined(p, typeof(BindingValueAttribute)));
foreach (PropertyInfo property in properties)
{
var column = new DataGridViewColumn()
{
HeaderText = ((property.GetCustomAttributes(true)[0]) as BindingValueAttribute).Value
};
Columns.Add(column);
}
}
}
public class BindedDataGrid : DataGridView
{
public BindedDataGrid()
{
}
public BindedDataGrid(Type bindType)
{
IEnumerable<PropertyInfo> properties = bindType.GetProperties().Where(p => Attribute.IsDefined(p, typeof(BindingValueAttribute)));
foreach (PropertyInfo property in properties)
{
var prop = property.GetCustomAttributes(true)[0];
if (prop is BindingValueAttribute)
{
var column = new DataGridViewColumn()
{
HeaderText = property.Name
};
column.CellTemplate = new DataGridViewTextBoxCell();
Columns.Add(column);
}
}
}
}
public class BindingValueAttribute : Attribute
{
public string Value { get; set; }
}
public class BindOne
{
[BindingValueAttribute()]
public string Name { get; set; }
[BindingValueAttribute()]
public int Age { get; set; }
}
- 首先使 BindedDataGrid none 通用
创建非参数化构造函数
private void InitializeComponent()
{
this.bindedDataGrid1 = new PlayingWithThread.BindedDataGrid(typeof(BindOne));
((System.ComponentModel.ISupportInitialize)(this.bindedDataGrid1)).BeginInit();
我延长了DataGridView
。我想将新控件添加到工具箱而不添加对不同程序集的引用(使用右键单击选项 "Choose Items")。控件在窗体的同一个项目中,我不想将它们分开。我怎样才能做到这一点?
谢谢。
编辑:如果它不是用户控件,则不可能重复有关用户控件的问题。
编辑 2: 代码本身(这是一个进行中的工作。尚未完成):
class BindedDataGrid<T> : DataGridView
{
public BindedDataGrid()
{
InitializeComponent();
IEnumerable<PropertyInfo> properties = typeof(T).GetProperties().Where(p => Attribute.IsDefined(p, typeof(BindingValueAttribute)));
foreach (PropertyInfo property in properties)
{
var column = new DataGridViewColumn()
{
HeaderText = ((property.GetCustomAttributes(true)[0]) as BindingValueAttribute).Value
};
Columns.Add(column);
}
}
}
public class BindedDataGrid : DataGridView
{
public BindedDataGrid()
{
}
public BindedDataGrid(Type bindType)
{
IEnumerable<PropertyInfo> properties = bindType.GetProperties().Where(p => Attribute.IsDefined(p, typeof(BindingValueAttribute)));
foreach (PropertyInfo property in properties)
{
var prop = property.GetCustomAttributes(true)[0];
if (prop is BindingValueAttribute)
{
var column = new DataGridViewColumn()
{
HeaderText = property.Name
};
column.CellTemplate = new DataGridViewTextBoxCell();
Columns.Add(column);
}
}
}
}
public class BindingValueAttribute : Attribute
{
public string Value { get; set; }
}
public class BindOne
{
[BindingValueAttribute()]
public string Name { get; set; }
[BindingValueAttribute()]
public int Age { get; set; }
}
- 首先使 BindedDataGrid none 通用
创建非参数化构造函数
private void InitializeComponent() { this.bindedDataGrid1 = new PlayingWithThread.BindedDataGrid(typeof(BindOne)); ((System.ComponentModel.ISupportInitialize)(this.bindedDataGrid1)).BeginInit();