Not Coder

coding 是一种思维方式

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
扩展模型示例:
下面的程序段扩展了一个容器
 
 1
using System;
 2using System.Collections.Generic;
 3using System.Text;
 4using CMC.Controls.Base;
 5using System.Drawing;
 6using System.Drawing.Drawing2D;
 7
 8//扩展的名字空间必须以"CMC.Libs."开头 否者不能正常识别
 9namespace CMC.Libs.Normal.Container
10{
11    /// <summary>
12    /// 派生类必须以CMC.Controls.Base.Control或其派生类为基类 否者不能正常识别
13    /// </summary>

14    public class ExtendCMC : CMC.Controls.NormalContainerControl
15    {
16        private CMC.Controls.Shapes.Ellipse _Ellipse = new CMC.Controls.Shapes.Ellipse(100100);
17        public float Width
18        {
19            get return _Ellipse.Width; }
20            set
21            {
22                if (_Ellipse.Width != value)
23                {
24                    _Ellipse.Width = value;
25                    NeedRebuild = true;
26                }

27            }

28        }

29        public float Height
30        {
31            get return _Ellipse.Height; }
32            set
33            {
34                if (_Ellipse.Height != value)
35                {
36                    _Ellipse.Height = value;
37                    NeedRebuild = true;
38                }

39            }

40        }
41        protected override void InitGraphicsPath(ref CMC.Controls.Base.Chain<System.Drawing.Drawing2D.GraphicsPath> GraphicsPaths)
42        {
43            if (GraphicsPaths.IsEmpty)
44            {
45                GraphicsPaths.AddItem(new GraphicsPath());
46            }

47            GraphicsPaths.First.Value.AddPath(_Ellipse.GraphicsPath, false);
48        }

49    }

50}

51
下面的代码将CMC控件添加到窗体中
 1using System;
 2using System.Collections.Generic;
 3using System.ComponentModel;
 4using System.Data;
 5using System.Drawing;
 6using System.Text;
 7using System.Windows.Forms;
 8
 9namespace ExtendCMC
10{
11    public partial class Form1 : Form
12    {
13        public Form1()
14        {
15            InitializeComponent();
16            this.Width = 800;
17            this.Height = 600;
18
19            CMC.CMCControl cc = new CMC.CMCControl();
20            cc.Dock = DockStyle.Fill;
21            this.Controls.Add(cc);
22            CMC.Chart c = cc.Chart;
23            CMC.Libs.Normal.Container.ExtendCMC ec = new CMC.Libs.Normal.Container.ExtendCMC();
24            c.AddControl(ec);
25            ec.MoveBy(100100);
26        }

27    }

28}

dll+范例+帮助下载但 
控件可以随便使用,也欢迎发信询问细节,但暂时不考虑提供源代码。
posted on 2008-01-11 22:11  Not Coder  阅读(1966)  评论(1编辑  收藏  举报