自定义设计器的模型和代码
最近一直在研究根设计器的代码与模型的相互序列化问题,终于有点结果了.
这是测试代码:
对应的模型如下,用户可以用鼠标(很快会加入连线等其它item)设置节点大小和位置,以及在属性编辑器中更改属性,并可以立刻反映到代码上,对应的代码更改后也可以立刻会反映到模型上.
下面是在SharpDevelop(open source's IDE)中的截图,在VS2005也已经通过.
准备在这个项目告一段落后把这些内容整理出来,自定义设计器可以用到很多地方,如故障建模,工作流建模等....
这是测试代码:
using System;
using System.Collections.Generic;
using System.Text;
using Incon.IBuilder.Core;
namespace ShapeDevelopTest
{
class MyTestClass:Incon.IBuilder.Core.Module
{
public MyTestClass()
{
InitializeComponent();
}
private void InitializeComponent()
{
Incon.IBuilder.Core.Node Node2;
Incon.IBuilder.Core.Node Node1;
Incon.IBuilder.Core.Node Node3;
Node2 = new Incon.IBuilder.Core.Node();
Node1 = new Incon.IBuilder.Core.Node();
Node3 = new Incon.IBuilder.Core.Node();
//
// Node2
//
Node2.Location = new System.Drawing.Point(201, 161);
Node2.Owner = null;
Node2.Size = new System.Drawing.Size(80, 40);
Node2.Text = "温度高";
//
// Node1
//
Node1.Location = new System.Drawing.Point(80, 161);
Node1.Owner = null;
Node1.Size = new System.Drawing.Size(80, 40);
Node1.Text = "压力低";
//
// Node3
//
Node3.Location = new System.Drawing.Point(160, 41);
Node3.Owner = null;
Node3.Size = new System.Drawing.Size(80, 40);
Node3.Text = "泄漏";
Node3.AfterCompute += new Incon.IBuilder.Core.AfterComputeEventHandler(this.Node3AfterCompute);
//
// MyTestClass
//
this.Nodes.Add(Node3);
this.Nodes.Add(Node1);
this.Nodes.Add(Node2);
this.Text = "模型知识123";
}
private System.ComponentModel.Container components;
void Node3AfterCompute(object sender, System.EventArgs e)
{
System.Windows.Forms.MessageBox.Show( (sender as Node ).Text);
}
}
}
using System.Collections.Generic;
using System.Text;
using Incon.IBuilder.Core;
namespace ShapeDevelopTest
{
class MyTestClass:Incon.IBuilder.Core.Module
{
public MyTestClass()
{
InitializeComponent();
}
private void InitializeComponent()
{
Incon.IBuilder.Core.Node Node2;
Incon.IBuilder.Core.Node Node1;
Incon.IBuilder.Core.Node Node3;
Node2 = new Incon.IBuilder.Core.Node();
Node1 = new Incon.IBuilder.Core.Node();
Node3 = new Incon.IBuilder.Core.Node();
//
// Node2
//
Node2.Location = new System.Drawing.Point(201, 161);
Node2.Owner = null;
Node2.Size = new System.Drawing.Size(80, 40);
Node2.Text = "温度高";
//
// Node1
//
Node1.Location = new System.Drawing.Point(80, 161);
Node1.Owner = null;
Node1.Size = new System.Drawing.Size(80, 40);
Node1.Text = "压力低";
//
// Node3
//
Node3.Location = new System.Drawing.Point(160, 41);
Node3.Owner = null;
Node3.Size = new System.Drawing.Size(80, 40);
Node3.Text = "泄漏";
Node3.AfterCompute += new Incon.IBuilder.Core.AfterComputeEventHandler(this.Node3AfterCompute);
//
// MyTestClass
//
this.Nodes.Add(Node3);
this.Nodes.Add(Node1);
this.Nodes.Add(Node2);
this.Text = "模型知识123";
}
private System.ComponentModel.Container components;
void Node3AfterCompute(object sender, System.EventArgs e)
{
System.Windows.Forms.MessageBox.Show( (sender as Node ).Text);
}
}
}
对应的模型如下,用户可以用鼠标(很快会加入连线等其它item)设置节点大小和位置,以及在属性编辑器中更改属性,并可以立刻反映到代码上,对应的代码更改后也可以立刻会反映到模型上.
下面是在SharpDevelop(open source's IDE)中的截图,在VS2005也已经通过.
准备在这个项目告一段落后把这些内容整理出来,自定义设计器可以用到很多地方,如故障建模,工作流建模等....
posted on 2005-12-02 02:52 CBuilder 阅读(2192) 评论(10) 编辑 收藏 举报