首Html代码

学有所用,不然就失去意义。

子标题

导航

自定义组件 Collection(集合类)

 

 

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
{
    
class 动态 : Label
    
{
        
private List<TypedFilter> _filters = new List<TypedFilter>();

        [Category(
"BusinessObjectControl")]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        [Editor(
typeof(FilterCollectionEditor), typeof(System.Drawing.Design.UITypeEditor))]
        
public List<TypedFilter> Filters
        
{
            
get return _filters; }
            
set { _filters = value; }
        }

    }


    
public class TypedFilter
    
{
        
private string _dataPropertyName = "Name";
        
public string DataPropertyName
        
{
            
get return _dataPropertyName; }
            
set { _dataPropertyName = value; }
        }


        
private int _value = 0;
        
public int Value
        
{
            
get return _value; }
            
set { _value = value; }
        }


        
public override string ToString()
        
{
            
return _dataPropertyName + " = " + _value.ToString();
        }

    }


    
class FilterCollectionEditor : CollectionEditor
    
{
        
public FilterCollectionEditor(Type type)
            : 
base(type)
        
{
        }

    }

}

其实能实现简单的集合类...还是很多地方不足,,,如果有幸遇到高手还希望帮忙解答...

1.以上的例子只能产生局部变量.不会产生全局的..请问如何解决

我能不能生成,我想要的变量,比如局部,或者全局...

2.public class TypedFilter:Control  这样做结果是删除控件后,变量不会删除

以上代码希望对你有帮助,,尤其是做这方面的.

posted on 2009-02-05 10:52  tssing  阅读(1417)  评论(3编辑  收藏  举报

页脚Html代码