![](https://www.cnblogs.com/images/cnblogs_com/tssing/QQ截图未命名.jpg)
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;
using System.ComponentModel.Design;
using Mylib;
namespace MyLib
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
class 动态 : Label
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
private List<TypedFilter> _filters = new List<TypedFilter>();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
[Category("BusinessObjectControl")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Editor(typeof(FilterCollectionEditor), typeof(System.Drawing.Design.UITypeEditor))]
public List<TypedFilter> Filters
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return _filters; }
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{ _filters = value; }
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public class TypedFilter
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
private string _dataPropertyName = "Name";
public string DataPropertyName
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return _dataPropertyName; }
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{ _dataPropertyName = value; }
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private int _value = 0;
public int Value
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return _value; }
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{ _value = value; }
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public override string ToString()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return _dataPropertyName + " = " + _value.ToString();
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
class FilterCollectionEditor : CollectionEditor
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
public FilterCollectionEditor(Type type)
: base(type)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
}
}
}
其实能实现简单的集合类...还是很多地方不足,,,如果有幸遇到高手还希望帮忙解答...
1.以上的例子只能产生局部变量.不会产生全局的..请问如何解决
我能不能生成,我想要的变量,比如局部,或者全局...
2.public class TypedFilter:Control 这样做结果是删除控件后,变量不会删除
以上代码希望对你有帮助,,尤其是做这方面的.