您的位置:首页 > 其它

自定义控件 之 树型控件

2008-01-28 19:05 183 查看
要过年了,自己却要离开这个地方了....想着没什么好留下的...打算花一个周的时间..编写个树控件出来.留给公司吧.....也顺便学学编写控件.....

介绍:

前段时间, 做移动集团综合告警的时候,由于要实时的显示现有告警,所以,有开发过一个树控件,支持了结点的动态生成....但是,由于针对性太强,不能够得到复用,以至经理要求做一个新的树型控件出来,因此,也就有了这篇文章...

废话:

由于是第一次弄这样的东西,如果有什么不正确的地方,还希望各个老大帮忙指出....

第一步:编写一个容器控件ContentControl..

问题描述:

是从Control派生,还是从UserControl派生,且,是否支持用户使用本控件后,在vs ide 中可以直接拖控件到该控件中.....

解决方法:由于编写该控件的目的,是自定一个树控件,因此,没必要支持把别的控件拖动到本控件中....如果实在是要支持这样的,可以这样设置...

[Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design")]

public class ContentControl : Control

using System;

using System.Collections.Generic;

using System.Text;

using System.Windows.Forms;

namespace BOCO.Controls

第三步:正如上面看到的,TreeItem,这个东西是什么?TreeItem,表示的是树节点的tag,同时,也是一个逻辑上的树(好了,难点来了)

首先,怎么设计这个逻辑意义上的树..

树节点,一般有两种形式,一是叶子节点,二是树枝节点(不知道组合模式可不可以用到这个地方)

树叶子节点接口:IChild<T>(因为在看范型的东西,所以,使用下下)


public interface IChild<T> where T: class, IChild<T>

树树枝节点接口:

using System;

using System.Collections.Generic;

using System.Text;

namespace BOCO.Controls

如上,CollectionList是什么东西呢?这个是实现接口IBindingList的东西,那IBindingList这个又是什么呢?好象是实现了这个接口的,就可以在后台模型更改后,反映到前台来的吧.....

(未完....)

第四步:节点事件的参数:TreeNodeEventArgs


using System;

using System.Collections.Generic;

using System.Text;

using System.Windows.Forms;

namespace BOCO.Controls

第五步:TreeControl,继承ContentControl,实现ITreeControl接口

using System;

using System.Collections.Generic;

using System.Text;

using System.Windows.Forms;

namespace BOCO.Controls

第六步:树节点的层次应支持可配置

未完....明天继续....
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: