ECPropertyPane控件


我们在Mstn中查看元素属性时一般会用到“属性”对话框,如下所示:

此对话框中在后台通过庞大的EC机制,可以让我们查看到不同类型元素的不同格式的属性。这里显示属性的控件是ECPropertyPane类型,此类型在“C:\Program Files\Bentley\MicroStation CONNECT Edition\MicroStation\Assemblies\ECFramework\Bentley.ECObjects3.dll”程序集中。我们也可以在我们自己的Form窗口中添加这样一个控件去显示指定的ECInstance,如下链接是我们的测试项目:

communities.bentley.com/.../ECPropertyPaneDemo.7z

下载编译后,启动Mstn,打开keyin命令窗口,执行keyin命令“mdl load ECPropertyDemo; ecpropertypanedemo test”,然后会看到如下对话框:

可以看到在我们自己的窗体中显示了一个跟“属性”对话框中类似的属性显示控件。接下来我们看一下代码中是如何实现的。在此窗体对应的ECPropertyPaneDemo类中,我们在“Load”事件中执行了如下代码:

private void ECPropertyPaneDemo_Load(object sender, EventArgs e)
        {
            IECSchema ecSchema = new ECSchema(NameECSchema, 1, 0, NSPre);
            IECClass ecClass = ecSchema.AddClass(NameECClass);
            ecClass.IsDomainClass = true;
            IECProperty ecprop1 = ecClass.AddProperty(NameProp1, ECObjects.StringType);
            ecprop1.DisplayLabel = "MyProp1";
            IECProperty ecprop = ecClass.AddProperty(NameProp2, ECObjects.StringType);
            ecprop.DisplayLabel = "MyProp2";
            ecprop.IsReadOnly = true;
            IECInstance instance = ecClass.CreateInstance();
            instance.SetAsString("MyProp1", "123");
            instance.SetAsString("MyProp2", "abc");
            ECInstanceList instanceList = new ECInstanceList();
            instanceList.Add(instance);
            ECInstanceListSet instanceListSet = new ECInstanceListSet();
            instanceListSet.Add(instanceList);
            bool showNullValues = false;
            string stateFileNameRoot = "Tester";
            ECInstanceListSet editListSet = instanceListSet;
            ECPropertyPane propertyPane = new ECPropertyPane(editListSet, null, null, "test", showNullValues, true, true, stateFileNameRoot, 200);
            propertyPane.DragDropMonikerProvider = new MonikerProvider();
            propertyPane.Dock = DockStyle.Fill;
            this.Controls.Add(propertyPane);
        }

这段代码中,我们首先创建了用来显示属性的格式,即ECSchemaECClass等。然后我们创建了属性的实例,即IECInstance,对此实例做了简单的赋值。然后创建了ECPropertyPane的实例,将前面创建的属性实例传递给了ECPropertyPane的构造函数,最后将ECPropertyPane的实例Add到窗体类的Controls属性中。此外我们还将ECPropertyPane实例的“Dock”属性设置为“DockStyle.Fill”,这样在拖动窗体,改变其大小时,我们的ECPropertyPane控件会随着窗体大小的改变而改变。