第八期视频回放

点击查看【bilibili】

第八期代码及课件下载地址

代码及课件下载地址

第八期直播内容文字版

界面设计简述

引言

  1. 在我们掌握了交互式工具的使用方法后,在使用过程中会发现:虽然工具中拥有多种交互的手段,但仅凭工具中鼠标,特殊按键与信息提示等交互方法,没有办法同时对多个信息进行展示,也不够直观。而界面不仅可以自定义展示内容,同时也可根据用户的行为实现数据交换,因此掌握界面的制作方法便显得十分重要。基于系列直播课程开办的初衷,凭借上手难度低,学习资料丰富的优势,本次与大家分享的是Winform界面创建及常用控件的使用方法。

WinForm概念简述

  1. WinForm Windows Form 的简称,是基于 .NET Framework 平台的客户端(PC软件)开发技术,一般使用 C# 编程。WinForm 编程需要创建「Windows窗体应用程序」项目。Windows 窗体应用程序是 C# 语言中的一个重要应用,也是 C# 语言最常见的应用。使用 C# 语言编写的 Windows 应用程序与 Windows 操作系统的界面类似,每个界面都是由窗体构成的,并且能通过鼠标单击、键盘输入等操作完成相应的功能。其具有以下优势:<br />1.用户体验好,上手简单,界面反应速度快<br />2.单机版程序,适合数据敏感使用场景<br />3.开发便利,无需部署云端,.NET 提供了大量 Windows 风格的控件和事件

WinForm和WPF

  1. 提到WinForm就无可避免的会提到WPF,二者都是为了创建桌面客户端应用程序的 UI 框架。<br /> WinForm可用于设计窗体和可视控件,以创建丰富的基于Windows的应用程序。Windows窗体提供了一套丰富的控件,并且开发人员可以定义自己有特色的新的控件。它的设计器是使用Visual Studio自带的控件进行拖拽,设置控件对应的属性,事件。<br /> WPF能做到分离界面设计人员与开发人员的工作,提供多媒体交互用户图形界面。它的设计器是用xaml语言来写的,就像写html一样。<br />对于二者的区别,主要有以下几点:
  • WinForm是“前后端”不分离的,WPF是前后端分离的。WinForm的设计器和CS文件的编码“耦合度”太高了,不能独立进行设计页面
  • WPF的UI更加华丽,扩展性较高,但前提是需要会写样式,同时内存占用较高
  • WPF 可以实现数据类似vue=>data绑定,WinForm没有这种方式,控件值需要内部赋值才能起到与WPF相同的效果
  • WPF支持控件自适应
  • Winform上手难度低,WPF的制作需要学习xaml语法,布局方面难度较大

相关资料:
WinForm官方入门教程
WPF官方入门教程

WinForm界面开发方法

创建WinForm应用

  1. 首先需要明确的是:WinForm界面开发作为通用的界面设计开发方式,使用范围不仅局限于MicroStation二次开发,还可使用到其他的程序中,因此,若您希望获得更多WinForm的开发技巧,可以在网上获取更多的相关资料。<br /> 对于MicroStation二次开发来说,我们首先需要在工程中创建一个新的项目,具体方式右键工程调出菜单,点击添加后直接选择创建WimForm界面或点击新项目调出文件创建菜单。<br />![1.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646961270642-fdd41bb6-e096-4c7f-acae-8832539d157a.png#clientId=u232944d7-fcdf-4&crop=0&crop=0&crop=1&crop=1&from=drop&id=ue54e7cea&margin=%5Bobject%20Object%5D&name=1.png&originHeight=497&originWidth=654&originalType=binary&ratio=1&rotation=0&showTitle=false&size=51008&status=done&style=none&taskId=ufcec3011-6afe-4406-a627-8d8086dbd06&title=)<br />**图1 工程菜单界面**<br /> 若采用第一种方式创建WinForm菜单,需要选择菜单界面中的WindowForm选项,同时可在下方对该文件进行命名,完成后点击添加。<br />![image.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646961424786-40602f29-bf71-457f-8c1d-a87b7258c5f0.png#clientId=u232944d7-fcdf-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=654&id=u4077c38d&margin=%5Bobject%20Object%5D&name=image.png&originHeight=654&originWidth=940&originalType=binary&ratio=1&rotation=0&showTitle=false&size=43717&status=done&style=none&taskId=u4c37a7ed-4bdb-4ec6-80ad-cc07542f329&title=&width=940)<br />**图2 添加项目界面**

WinForm界面设计

添加完成之后会生成一个WinForm界面,此时我们可以选择左边的Toolbox,其中提供了很多控件,方便应对不同的交互需求。
image.png
图3 WinForm界面
image.png
图4 Toolbox界面
当我们需要使用控件时,只需要从工具箱中拉取对应的控件到界面中,使用拖拽或者调整控件中属性的方法对控件尺寸进行调整,此时最简单的界面就已经布置完成。这里我们使用Button控件来进行演示,可以看到,从工具箱中拖拽出来后,可以使用鼠标拖拽或属性值修改的方式来实现界面的设计。1.gif
图5 WinForm界面设计
对于WinForm界面的设计来说,控制界面行为的有属性与事件,属性指的是状态,比如说Button中的属性有按钮的名称,大小,位置,颜色等等,而事件有点像参数化工具中的事件,当我们做出指定行为时若注册了事件那么就会触发该事件。属性和行为的修改不仅可以通过界面,也可通过代码来实现。其实界面生成与代码本质上是一致的,只不过在界面上的操作会自动生成对应的属性设置或者注册对应的事件,更加方便与高效。
image.png
图6 界面修改属性
image.png
图7 代码修改属性
image.png
图8 界面设置事件

  1. public Form1()
  2. {
  3. InitializeComponent();
  4. button1.Text = "确认";
  5. button1.AutoSizeChanged += Button1_AutoSizeChanged;
  6. }
  7. private void Button1_AutoSizeChanged(object sender, EventArgs e)
  8. {
  9. }

WinForm常用控件及使用方法介绍

  1. 正如上文所述,WinForm使用属性与事件实现数据与用户的信息传递。对于MicroStation二次开发而言,界面的控件主要用于用户信息与MicroStation软件中数据的交换。常用的控件有ButtonCheckBoxComboBoxLabelListBoxPanelProgressBarRadioButtonTextBoxTreeView等,在这里我们对常用控件的使用方法进行简单介绍。<br />![image.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646899895192-e3d52c18-f118-42a4-837b-f277c3705bf4.png#clientId=ufdf9e1f5-98b7-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=404&id=n8VCA&margin=%5Bobject%20Object%5D&name=image.png&originHeight=505&originWidth=1261&originalType=binary&ratio=1&rotation=0&showTitle=false&size=106524&status=done&style=none&taskId=u9d07c7c6-a617-44c4-a495-187cfe82df5&title=&width=1008.8)<br />**图9 WinForm常用控件**

WinForm界面
  1. 对于WinForm界面来说,若需要对界面进行定制,我们便需要修改其属性,较为常用的是修改WinForm标题栏中的文字大小,字体,或者对界面图表进行设置,包括是否启动最大化,最小化按钮等。

修改界面图标

当我们需要修改界面图标时,需要点击Icon,导入指定的后缀为.ico的文件,此时便会替换为指定图标文件。
Screenshot 2022-03-11 140211.png
图10 WinForm界面属性面板

锁定/解锁最大/小化按钮
  1. 当我们需要锁定或者解锁最大或最小化按钮,此时需要对最大化/最小化窗口进行设置。<br />![Screenshot 2022-03-11 140604.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646978808743-a53eb3cb-9722-42e2-8718-ef64573cc861.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=411&id=ubc2ea676&margin=%5Bobject%20Object%5D&name=Screenshot%202022-03-11%20140604.png&originHeight=411&originWidth=546&originalType=binary&ratio=1&rotation=0&showTitle=false&size=61652&status=done&style=none&taskId=u58bb1281-c6d7-4f52-a47c-be0c6cac37e&title=&width=546)<br />**图11 WinForm界面属性面板**

修改界面标题文字
  1. 当我们需要修改标题的文字时,可以在属性名为Text处进行修改。<br />![Screenshot 2022-03-11 140856.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646978963831-588c8899-a464-4f5f-9299-b7d2ef56d16a.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=418&id=u2a158407&margin=%5Bobject%20Object%5D&name=Screenshot%202022-03-11%20140856.png&originHeight=418&originWidth=543&originalType=binary&ratio=1&rotation=0&showTitle=false&size=62140&status=done&style=none&taskId=ufa2e96d4-a90a-471e-83e3-fa24ea5fa8d&title=&width=543)<br />**图12 WinForm界面属性面板**

Button控件
  1. Button控件即按钮,一般用于提供给用户进行确认信息无误后执行的操作。<br />![image.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646980404988-f84efdcb-b75c-45b8-9c4d-50c9ca93197f.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=57&id=b9a6e&margin=%5Bobject%20Object%5D&name=image.png&originHeight=57&originWidth=109&originalType=binary&ratio=1&rotation=0&showTitle=false&size=1686&status=done&style=none&taskId=u169c553f-11f0-42fb-8ffd-e9427273679&title=&width=109)<br />**图13 Button控件**

常用事件
  1. 常用的事件主要为**点击按钮**触发事件。双击Click后的空白处或直接双击界面上的该控件后会自动生成代码注册该事件,并跳转到触发该事件后执行的方法,在方法中补充对应的业务函数。<br />![Screenshot 2022-03-11 141442.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646979306265-5fc8a79d-7326-4258-babd-13cdefea0ac3.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=417&id=u0159379c&margin=%5Bobject%20Object%5D&name=Screenshot%202022-03-11%20141442.png&originHeight=417&originWidth=545&originalType=binary&ratio=1&rotation=0&showTitle=false&size=63621&status=done&style=none&taskId=ub4055e79-8602-47a0-81c8-f63d7914852&title=&width=545)<br />**图14 Button控件属性面板**<br />![Screenshot 2022-03-11 141845.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646979551582-a265df4f-4dec-42ea-acba-d87fb223c277.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=245&id=uaf666d67&margin=%5Bobject%20Object%5D&name=Screenshot%202022-03-11%20141845.png&originHeight=245&originWidth=707&originalType=binary&ratio=1&rotation=0&showTitle=false&size=76875&status=done&style=none&taskId=u90a2e1ad-a408-407c-adbf-a778a30916e&title=&width=707)<br />**图15 代码中自动添加的事件**
  1. private void button1_Click_1(object sender, EventArgs e)
  2. {
  3. }

CheckBox控件
  1. 复选框主要用于选择单个/多个条件时的条件选择。<br />![image.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646980450965-f0294aac-c459-400d-ab53-ab20e3b3e775.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=41&id=nvI0E&margin=%5Bobject%20Object%5D&name=image.png&originHeight=41&originWidth=118&originalType=binary&ratio=1&rotation=0&showTitle=false&size=2449&status=done&style=none&taskId=u8562523f-c3bc-480a-acd5-260bd336f7e&title=&width=118)<br />**图16 CheckBox控件**

常用事件
  1. 常用的事件主要为在用户**点击复选框**时选择状态的更改触发事件。双击CheckedChanged后的空白处或直接双击界面上的该控件后会自动生成代码注册该事件,并跳转到触发该事件后执行的方法,在方法中补充对应的业务函数。<br />![Screenshot 2022-03-11 142814.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646980118131-4defba75-f992-435f-bbd9-a25b88c0fb6e.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=415&id=u5df4d59b&margin=%5Bobject%20Object%5D&name=Screenshot%202022-03-11%20142814.png&originHeight=415&originWidth=541&originalType=binary&ratio=1&rotation=0&showTitle=false&size=72614&status=done&style=none&taskId=u0fb5e42c-f0ec-47aa-b44b-440e4865b8d&title=&width=541)<br />**图17 CheckBox控件属性面板**<br />![Screenshot 2022-03-11 142915.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646980183084-1e2b4efe-f9c3-4d08-89bf-d1d1a2273b41.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=267&id=ue4cfd0df&margin=%5Bobject%20Object%5D&name=Screenshot%202022-03-11%20142915.png&originHeight=267&originWidth=895&originalType=binary&ratio=1&rotation=0&showTitle=false&size=99505&status=done&style=none&taskId=u017f9e07-3c42-481e-8e8a-69b8737a556&title=&width=895)<br />**图18 代码中自动添加的事件**
  1. private void checkBox1_CheckedChanged(object sender, EventArgs e)
  2. {
  3. }

常用属性
  1. 我们通过复选框的属性**查看或者修改选择状态**,以便达到获取用户交互信息的目的,方法为获取或者修改该复选框的Checked属性,若为true则为选中状态,反之则反。<br />![image.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646980280825-b8abf451-0ecc-4920-8702-51ba80c806e4.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=74&id=u7291acaf&margin=%5Bobject%20Object%5D&name=image.png&originHeight=74&originWidth=441&originalType=binary&ratio=1&rotation=0&showTitle=false&size=12598&status=done&style=none&taskId=u43ffe766-29a3-4b93-88e8-ff674f3acac&title=&width=441)<br />**图19 复选框的选中属性**

ComboBox控件
  1. 下拉框用于多种选项的单项选择,它使用滚动的方式呈现出可供选择的所有项目。<br />![image.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646981404605-f3542c0b-14cf-4071-8064-0bb5c4fbbaac.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=45&id=ufb0d9ca2&margin=%5Bobject%20Object%5D&name=image.png&originHeight=45&originWidth=168&originalType=binary&ratio=1&rotation=0&showTitle=false&size=714&status=done&style=none&taskId=u25c2c5cf-89ac-41db-b39e-d389f2d2668&title=&width=168)<br />**图20 ComboBox控件**

常用事件
  1. 当我们**点击下拉框**时,可能需要动态的对下拉框中的内容进行补充。双击DropDown后的空白处会自动生成代码注册该事件,并跳转到触发该事件后执行的方法,在方法中补充对应的业务函数。<br />![Screenshot 2022-03-11 144750.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646981296947-e577724b-ff92-4a5f-956c-bd6885d7a77e.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=414&id=u4b274caf&margin=%5Bobject%20Object%5D&name=Screenshot%202022-03-11%20144750.png&originHeight=414&originWidth=546&originalType=binary&ratio=1&rotation=0&showTitle=false&size=57957&status=done&style=none&taskId=u19bf21f4-99cb-492e-aeb9-16b894f64c3&title=&width=546)<br />**图21 ComboBox控件属性面板**<br />![Screenshot 2022-03-11 150604.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646982387436-937913ef-6d77-48f3-af9a-e2c4888ec599.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=241&id=uf3608658&margin=%5Bobject%20Object%5D&name=Screenshot%202022-03-11%20150604.png&originHeight=241&originWidth=1002&originalType=binary&ratio=1&rotation=0&showTitle=false&size=103159&status=done&style=none&taskId=u26001e67-188f-43ef-baca-b29334dea46&title=&width=1002)<br />**图22 代码中自动添加的事件**
  1. private void comboBox1_DropDown(object sender, EventArgs e)
  2. {
  3. }
  1. 当我们在下拉框中**选定指定项**时,可能需要针对选定的项执行一系列的操作。双击SelectedIndexChanged后的空白处或直接双击界面上的控件后会自动生成代码注册该事件,并跳转到触发该事件后执行的方法,在方法中补充对应的业务函数。<br />![Screenshot 2022-03-11 150452.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646982315869-fa7484b3-8b25-4de0-bee0-9448f33e28a5.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=417&id=NPDYO&margin=%5Bobject%20Object%5D&name=Screenshot%202022-03-11%20150452.png&originHeight=417&originWidth=543&originalType=binary&ratio=1&rotation=0&showTitle=false&size=66219&status=done&style=none&taskId=u9eea5336-51e4-4d6d-9922-d7758c9bd63&title=&width=543)<br />**图23 ComboBox控件属性面板**<br />![Screenshot 2022-03-11 150604.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646982413214-9edeb450-d96b-4f9a-b8d7-4c686e44812f.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=241&id=u4e68b9d3&margin=%5Bobject%20Object%5D&name=Screenshot%202022-03-11%20150604.png&originHeight=241&originWidth=1002&originalType=binary&ratio=1&rotation=0&showTitle=false&size=102774&status=done&style=none&taskId=u776e15eb-2695-44c7-8c45-de69878694e&title=&width=1002)<br />**图24 代码中自动添加的事件**
  1. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  2. {
  3. }

常用属性
  1. 当我们需要查看或者对下拉框添加项目的话,一方面我们可以通过下拉框中的Items属性进行项目的添加,另一方面我们可以使用代码执行下拉框项目的添加,修改与删除。<br />![Screenshot 2022-03-11 151247.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646982789941-38d04c08-9af5-4ebf-b583-4568e13445e0.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=416&id=u17933d18&margin=%5Bobject%20Object%5D&name=Screenshot%202022-03-11%20151247.png&originHeight=416&originWidth=546&originalType=binary&ratio=1&rotation=0&showTitle=false&size=53965&status=done&style=none&taskId=u64d02e3c-f315-4a0a-ace6-07509dcceb0&title=&width=546)<br />**图25 ComboBox控件属性面板**
  1. comboBox1.Items.Add("obj");//添加
  2. comboBox1.Items.Remove("obj");//删除
  3. comboBox1.Items.Clear();//清空列表
  4. bool isExist= comboBox1.Items.Contains("obj");//查询

Label控件
  1. 标签主要用于信息示意,给用户输入或输出提供帮助。<br />![image.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646983060665-91a0991e-923f-442c-bf1a-73420d90ee67.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=37&id=u36d20ad1&margin=%5Bobject%20Object%5D&name=image.png&originHeight=37&originWidth=72&originalType=binary&ratio=1&rotation=0&showTitle=false&size=1570&status=done&style=none&taskId=u5d1c97c5-b85b-4763-b1d9-79b50111fd9&title=&width=72)<br />**图26 Label控件**

常用属性
  1. 最常用的即为修改Label控件的文字表示了,我们可以通过Label控件界面的Text属性进行修改,或者使用代码执行文字修改。<br />![Screenshot 2022-03-11 152911.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646983774085-fd64d826-9fec-472c-9827-37753f92c357.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=415&id=u1cdfc5ac&margin=%5Bobject%20Object%5D&name=Screenshot%202022-03-11%20152911.png&originHeight=415&originWidth=542&originalType=binary&ratio=1&rotation=0&showTitle=false&size=52252&status=done&style=none&taskId=u04d5944e-d38c-4623-97f1-081b3ef8372&title=&width=542)<br />**图27 Label控件属性面板**
  1. label1.Text = "test";//赋值

ListBox控件
  1. ListBox主要用于需要单选/多选项目,相比于ComboBox,他会将待选项全部呈现在列表中,并可进行多项选择。<br />![image.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646984227615-81cfed67-e414-4f31-9e4e-1ba853b028d3.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=127&id=u8d510bcc&margin=%5Bobject%20Object%5D&name=image.png&originHeight=127&originWidth=164&originalType=binary&ratio=1&rotation=0&showTitle=false&size=3652&status=done&style=none&taskId=udd5e4cae-bbee-4b05-b1df-2da60c3772d&title=&width=164)<br />**图28 ListBox控件**

常用事件
  1. 当我们在ListBox中的选取项目修改时,可能需要执行对应的业务函数,此时就需要引入索引修改的事件。双击SelectedIndexChanged后的空白处或直接双击界面上的控件后会自动生成代码注册该事件,并跳转到触发该事件后执行的方法,在方法中补充对应的业务函数。<br />![image.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646984415450-bd0c470d-862d-4a0c-a147-c31c16b03269.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=0.9945&crop=1&from=paste&height=404&id=u671d1a5f&margin=%5Bobject%20Object%5D&name=image.png&originHeight=406&originWidth=542&originalType=binary&ratio=1&rotation=0&showTitle=false&size=64976&status=done&style=none&taskId=u278ea4a3-a0f6-4c82-9c91-2f488c5dcb5&title=&width=539)<br />**图29 ListBox控件属性面板**<br />![Screenshot 2022-03-11 154124.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646984511455-149f484b-2894-4a35-bd9e-fc00e3f8afaf.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=312&id=u78a43a6e&margin=%5Bobject%20Object%5D&name=Screenshot%202022-03-11%20154124.png&originHeight=312&originWidth=971&originalType=binary&ratio=1&rotation=0&showTitle=false&size=97514&status=done&style=none&taskId=uba6f7f62-573e-4b3e-b4d6-7f48e841078&title=&width=971)<br />**图30 代码中自动添加的事件**
  1. private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
  2. {
  3. }

常用属性
  1. 当我们需要查看或者对下拉框添加项目的话,一方面我们可以通过下拉框中的Items属性进行项目的添加,另一方面我们可以使用代码执行下拉框项目的添加,修改与删除。<br />![Screenshot 2022-03-11 154405.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646984668803-19988024-7b39-43ca-a4a6-7b2b3aeef73d.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=410&id=uf1a3dd56&margin=%5Bobject%20Object%5D&name=Screenshot%202022-03-11%20154405.png&originHeight=410&originWidth=544&originalType=binary&ratio=1&rotation=0&showTitle=false&size=58784&status=done&style=none&taskId=u60819f83-b0c2-4958-92e9-d28ce0bc27a&title=&width=544)<br />**图31 ListBox控件属性面板**
  1. listBox1.Items.Add("obj");//添加
  2. listBox1.Items.Remove("obj");//删除
  3. listBox1.Items.Clear();//清空列表
  4. bool isExist = listBox1.Items.Contains("obj");//查询
  1. ListBox中选择子项时,可以使用属性中的SelectionMode进行切换,分为:
  • SelectionMode.None:不允许选中
  • SelectionMode.One:只允许用户选择一项
  • SelectionMode.MultiExtended:允许选择多项,但选中的条目必须相邻
  • SelectionMode.MultiSimple:允许选择多项,可任意选中多个条目

Screenshot 2022-03-11 155222.png
图32 ListBox控件属性面板

Panel控件
  1. Panel是一个包含其他控件的控件。 可以使用 Panel 来组合控件的集合,例如一组 RadioButton 控件。 与其他容器控件(如 GroupBox 控件)一样,如果 Panel 控件的 Enabled 属性设置为 false,则也会禁用包含在Panel中的控件。<br />![image.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646986458602-7c96d41a-53a7-4c57-b6b1-a5692ef6dd08.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=155&id=ue5c8d04c&margin=%5Bobject%20Object%5D&name=image.png&originHeight=155&originWidth=277&originalType=binary&ratio=1&rotation=0&showTitle=false&size=4313&status=done&style=none&taskId=u0f816f8a-380e-4438-820d-6b1155d8627&title=&width=277)<br />**图33 Panel控件**
  1. m_previewPanel = new PreviewPanel(m_dgnModel);//初始化用户控制
  2. m_previewPanel.Dock = DockStyle.Fill;//设置模式为填充
  3. panel_view.Controls.Add(m_previewPanel);//将用户控制添加到面板中
  1. 例如下图,用于预览构件尺寸的UserControl被添加到Panel中。<br />![image.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646985973328-50ba711c-f54a-4107-a94e-01f477702dc0.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=290&id=u8b8aee38&margin=%5Bobject%20Object%5D&name=image.png&originHeight=290&originWidth=399&originalType=binary&ratio=1&rotation=0&showTitle=false&size=8405&status=done&style=none&taskId=uef3ddc1d-1ec7-4825-8d29-fad5fc54175&title=&width=399)<br />**图34 添加用户控件的Panel**

ProgressBar控件
  1. ProgressBar控件主要用于显示进度状态,当我们执行操作需要一定时间时,为了实时显示进度状态,就可添加该控件。使用该控件时需要设置进度条的最小值与最大值,当前进度条的值与步长,比如在下面这个例子中,进度条是为了实时显示复制状态。<br />![image.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646986517865-9b61c927-2901-44e2-8f38-3136ef370dba.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=58&id=ub93d77b0&margin=%5Bobject%20Object%5D&name=image.png&originHeight=58&originWidth=154&originalType=binary&ratio=1&rotation=0&showTitle=false&size=1629&status=done&style=none&taskId=u9615b082-f955-474d-a2ae-464fb771b16&title=&width=154)<br />**图35 ProgressBar控件**
  1. #region ProgressBar
  2. m_progressBar_copyprogress.Minimum = 1;//设置进度条的最小值
  3. m_progressBar_copyprogress.Maximum = 100;//设置进度条的最大值
  4. m_progressBar_copyprogress.Value = 1;//设置进度条的值
  5. m_progressBar_copyprogress.Step = 100 / m_selectedElems.Count;//设置进度条的步长
  6. #endregion
  7. for (int i=0;i<m_selectedElems.Count;i++)//遍历元素容器中的元素
  8. {
  9. using (ElementCopyContext copyContext = new ElementCopyContext(m_dgnModel))//复制元素
  10. {
  11. m_progressBar_copyprogress.PerformStep();//进度条按照步长推进
  12. copyContext.DoCopy(m_selectedElems[i]);//复制元素到当前的模型空间中
  13. }
  14. }
  15. m_progressBar_copyprogress.Value = 100;//设置进度条的值

RadioButton控件
  1. RadioButton控件主要用于单项选择,即在指定范围内的所有RadioButton控件只能有一个处于选中状态。<br />![image.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646986729750-59532450-5d3a-4af1-8d82-eac6ca58734f.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=48&id=ue44606d3&margin=%5Bobject%20Object%5D&name=image.png&originHeight=48&originWidth=127&originalType=binary&ratio=1&rotation=0&showTitle=false&size=3552&status=done&style=none&taskId=u7a5ca1b9-9590-430b-8a0a-50de68056ff&title=&width=127)<br />**图36 RadioButton控件**

常用事件
  1. 常用的事件主要为在用户**点击单选按钮**时选择状态的更改触发事件。双击CheckedChanged后的空白处或直接双击界面上的该控件后会自动生成代码注册该事件,并跳转到触发该事件后执行的方法,在方法中补充对应的业务函数。<br />![Screenshot 2022-03-11 162337.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646987039211-7b9d6b90-fc3e-49de-89dc-c99d3ea0d529.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=417&id=u05cd5a28&margin=%5Bobject%20Object%5D&name=Screenshot%202022-03-11%20162337.png&originHeight=417&originWidth=541&originalType=binary&ratio=1&rotation=0&showTitle=false&size=62011&status=done&style=none&taskId=ueb24e9d1-f424-4f03-83d2-62a1d4ae9ca&title=&width=541)<br />**图37 RadioButton控件属性面板 **<br />![Screenshot 2022-03-11 162432.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646987097654-09699fde-efa7-4acf-998b-fe8287f329bd.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=308&id=u4f592319&margin=%5Bobject%20Object%5D&name=Screenshot%202022-03-11%20162432.png&originHeight=308&originWidth=966&originalType=binary&ratio=1&rotation=0&showTitle=false&size=119216&status=done&style=none&taskId=u06622a87-7b9e-4316-86af-8ef01105cc6&title=&width=966)<br />**图38 代码中自动添加的事件**
  1. private void radioButton1_CheckedChanged(object sender, EventArgs e)
  2. {
  3. }

常用属性
  1. 当我们需要设置RadioButton的选中状态时,可以使用RadioButton中的Checked属性。 我们通过单选选项的属性**查看或者修改选择状态**,以便达到获取用户交互信息的目的,方法为获取或者修改该复选框的Checked属性,若为true则为选中状态,反之则反。<br />![Screenshot 2022-03-11 162657.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646987238016-6e18104c-e270-4fa4-ad9e-b9a90cb44e5d.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=410&id=u74237eaf&margin=%5Bobject%20Object%5D&name=Screenshot%202022-03-11%20162657.png&originHeight=410&originWidth=542&originalType=binary&ratio=1&rotation=0&showTitle=false&size=63245&status=done&style=none&taskId=u4fbec6e5-e744-4eed-b9a1-78c511286ec&title=&width=542)<br />**图39 RadioButton控件属性面板 **<br />![image.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646987303193-d8a03e65-fb66-435a-80b6-0414d2f446cd.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=88&id=ue3e06bed&margin=%5Bobject%20Object%5D&name=image.png&originHeight=88&originWidth=647&originalType=binary&ratio=1&rotation=0&showTitle=false&size=16902&status=done&style=none&taskId=ub66c4127-70f5-4927-a3b4-618588cd254&title=&width=647)<br />**图40 RadioButton的选中属性**

TextBox控件

常用事件
  1. 当我们需要**控制文本框的输入内容**时,比如限制文本框仅可输入中文,或者数字等,就需要添加KeyPress事件。双击KeyPress后的空白处会自动生成代码注册该事件,并跳转到触发该事件后执行的方法,在方法中补充对应的业务函数。<br />![Screenshot 2022-03-11 163303.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646987604843-5daeec72-0f12-40d8-98f4-bbe701e01daf.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=0.981&from=paste&height=420&id=u05eaf8c3&margin=%5Bobject%20Object%5D&name=Screenshot%202022-03-11%20163303.png&originHeight=420&originWidth=543&originalType=binary&ratio=1&rotation=0&showTitle=false&size=60072&status=done&style=none&taskId=u4e81a1b0-af2d-4687-9729-9fff005109a&title=&width=543)<br />**图41 TextBox控件属性面板 **<br />![Screenshot 2022-03-11 163512.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646987736255-6e13494b-5032-400b-b356-8675c1785abe.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=192&id=u8c1bfb40&margin=%5Bobject%20Object%5D&name=Screenshot%202022-03-11%20163512.png&originHeight=192&originWidth=964&originalType=binary&ratio=1&rotation=0&showTitle=false&size=71735&status=done&style=none&taskId=u8e1f8883-3de0-42eb-bcca-44057f3ce33&title=&width=964)<br />**图42 代码中自动添加的事件**<br /> 例如在本案例中,就添加了一个只允许在文本框中输入数字的机制。
  1. private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
  2. {
  3. if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar))//只允许输入数字与删除键
  4. {
  5. e.Handled = true;//返回成功
  6. }
  7. }
  1. 当我们需要在**文本框中的文字修改**后执行相应操作时,可以添加TextChanged事件。双击TextChanged后的空白处或直接双击界面上的该控件后会自动生成代码注册该事件,并跳转到触发该事件后执行的方法,在方法中补充对应的业务函数。<br />![Screenshot 2022-03-11 164011.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646988035746-7ab3d590-0058-4370-9120-7d68a3a85035.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=0.9834&from=paste&height=421&id=u776feab2&margin=%5Bobject%20Object%5D&name=Screenshot%202022-03-11%20164011.png&originHeight=421&originWidth=541&originalType=binary&ratio=1&rotation=0&showTitle=false&size=66122&status=done&style=none&taskId=u9b6c935f-44d9-4c4b-8058-635dca0057e&title=&width=541)<br />**图43 TextBox控件属性面板 **<br />![image.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646988106568-f412ece9-1a4d-4e94-8131-18ff712774bf.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=217&id=ub1123d7f&margin=%5Bobject%20Object%5D&name=image.png&originHeight=217&originWidth=979&originalType=binary&ratio=1&rotation=0&showTitle=false&size=92582&status=done&style=none&taskId=u04bf3c98-719b-4cdf-81a3-e05dc7c24ef&title=&width=979)<br />**图44 代码中自动添加的事件**
  1. private void textBox1_TextChanged(object sender, EventArgs e)
  2. {
  3. }

常用属性
  1. 当我们不允许用户输入,只将TextBox作为一个输出信息的载体时,可将Enabled设置为false。<br />![Screenshot 2022-03-11 164650.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646988432305-da4bc6da-537e-4d07-b9bd-1eab6c93234a.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=412&id=uf0fa8dde&margin=%5Bobject%20Object%5D&name=Screenshot%202022-03-11%20164650.png&originHeight=412&originWidth=547&originalType=binary&ratio=1&rotation=0&showTitle=false&size=61639&status=done&style=none&taskId=u78f7259d-7e0f-4073-850d-e2fd7542c83&title=&width=547)<br />**图44 TextBox控件属性面板**<br /> 当我们需要在TextBox控件中设置文字时,可在Text属性处直接添加文字,同时也可使用代码进行设置。<br />![Screenshot 2022-03-11 165040.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646988661079-660c43b8-d56b-41aa-af36-0bdfa19078c8.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=414&id=udd2c5e3f&margin=%5Bobject%20Object%5D&name=Screenshot%202022-03-11%20165040.png&originHeight=414&originWidth=544&originalType=binary&ratio=1&rotation=0&showTitle=false&size=52651&status=done&style=none&taskId=uc71dcc8d-7cba-406f-a613-8679eaa5dfd&title=&width=544)<br />**图45 TextBox控件属性面板**
  1. textBox1.Text = "Test";//设置文本框中文字信息

TreeView控件

image.png
图46 树状图控件

常用事件
  1. 当我们选择了指定树状图节点时,可能需要执行一些业务函数,此时需要添加NodeMouseClick事件。双击NodeMouseClick后的空白处会自动生成代码注册该事件,并跳转到触发该事件后执行的方法,在方法中补充对应的业务函数。<br />![Screenshot 2022-03-11 165547.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646988968556-ce6c95d8-3eb4-4599-8eaf-7c97b4bb3f01.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=0.9857&from=paste&height=419&id=uf4482f07&margin=%5Bobject%20Object%5D&name=Screenshot%202022-03-11%20165547.png&originHeight=419&originWidth=541&originalType=binary&ratio=1&rotation=0&showTitle=false&size=57652&status=done&style=none&taskId=ucec6cab2-7c7a-48df-b093-f271f518fe6&title=&width=541)<br />**图47 TreeView控件属性面板**<br />![Screenshot 2022-03-11 165738.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646989085969-c8ca7b42-31c5-40ef-b309-b4079ec6cfd4.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=214&id=ub88e590e&margin=%5Bobject%20Object%5D&name=Screenshot%202022-03-11%20165738.png&originHeight=214&originWidth=1119&originalType=binary&ratio=1&rotation=0&showTitle=false&size=98499&status=done&style=none&taskId=u0c2c94b1-592b-41ba-b1e6-eecc8b9bb9a&title=&width=1119)<br />**图48 代码中自动添加的事件**
  1. private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)//点击树状图节点时触发
  2. {
  3. AddECPropItems(e);//在用户控件界面添加EC属性框
  4. }

常用属性
  1. 当我们需要向树状图时,总是无可避免的涉及到节点的添加,删除以及嵌套,此时需要使用Nodes属性,若需要在节点上添加分支,则需要使用TreeNode类。
  1. treeView1.Nodes.Add("test");
  2. TreeNode node1 = new TreeNode("n1");
  3. treeView1.Nodes.Remove(node1);
  4. TreeNode node2 = new TreeNode("n2");
  5. treeView1.Nodes.Add(node2);
  6. TreeNode node3 = new TreeNode("n3");
  7. node2.Nodes.Add(node3);
  8. TreeNode node4 = new TreeNode("testNode");
  9. treeView1.Nodes.Add(node4);

image.png
图49 树状图显示结果

案例实战

  1. 为了展现在MicroStation二次开发中使用WinForm界面控件与MicroStation内的数据交互,这里我们使用三个案例进行展示,分别为可视化矩形梁生成工具,EC属性赋值工具与文件选择复制工具。<br />![image.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646989914708-1c3b61ef-a3c7-4d15-9758-bd3dd26aac62.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=525&id=uee0ad9eb&margin=%5Bobject%20Object%5D&name=image.png&originHeight=525&originWidth=549&originalType=binary&ratio=1&rotation=0&showTitle=false&size=29259&status=done&style=none&taskId=ue30e0cbf-53a6-4761-9f4b-f7accaca050&title=&width=549)

可视化矩形梁生成工具

  1. 该工具会根据用户输入的数据实时在Panel中的用户控件中对截面信息进行预览,确定截面信息无误后点击确认会启动交互式工具,根据用户输入的信息生成矩形梁截面,通过交互式工具用户点击的位置确认矩形梁的起点与终点。<br /> 该工具涉及到的WinForm控件有:LabelTextBoxButtonPanelUserControl(用户自定义控件)。<br />![image.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646990320510-42411733-8fff-41f1-845d-ebce2c8130cc.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=371&id=ub353cdfc&margin=%5Bobject%20Object%5D&name=image.png&originHeight=371&originWidth=1526&originalType=binary&ratio=1&rotation=0&showTitle=false&size=29513&status=done&style=none&taskId=u68daa6f5-a396-4dc2-948e-5c7f3824347&title=&width=1526)<br />**图50 工具流程图**<br />![image.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646990365724-1fb9eb2c-07c7-442a-a2a6-bfa9b137da38.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=358&id=u4d46b650&margin=%5Bobject%20Object%5D&name=image.png&originHeight=358&originWidth=1506&originalType=binary&ratio=1&rotation=0&showTitle=false&size=21906&status=done&style=none&taskId=u30850104-0c85-47c8-a6ef-9da81b4aa6c&title=&width=1506)<br />**图51 控件调用流程图**
  1. using Bentley.DgnPlatformNET;
  2. using Bentley.DgnPlatformNET.Elements;
  3. using Bentley.GeometryNET;
  4. using Bentley.MstnPlatformNET;
  5. using Bentley.MstnPlatformNET.WinForms;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.ComponentModel;
  9. using System.Data;
  10. using System.Drawing;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows.Forms;
  15. namespace WinformUIIntroduction.UI
  16. {
  17. public partial class BeamCreateMenu : Adapter// Form//
  18. {
  19. public static int m_width;//声明int值,用于记录梁宽度
  20. public static int m_height;//声明int值,用于记录梁高度
  21. private PreviewPanel m_previewPanel = null;//声明用户控制,用于预览梁轮廓
  22. private DgnModel m_dgnModel;//声明模型空间
  23. private DgnFile m_dgnFile;//声明文件
  24. private double m_uorPerMeter;//声明double值,用于记录屏幕分辨率与米之间的换算比例
  25. public BeamCreateMenu()
  26. {
  27. InitializeComponent();//初始化界面
  28. m_dgnFile = Session.Instance.GetActiveDgnFile();//获得当前的模型空间
  29. m_dgnModel = Session.Instance.GetActiveDgnModel();//获得当前的文件
  30. m_uorPerMeter = Session.Instance.GetActiveDgnModel().GetModelInfo().UorPerMeter;//分辨率单位转换为米
  31. m_previewPanel = new PreviewPanel(m_dgnModel);//初始化用户控制
  32. m_previewPanel.Dock = DockStyle.Fill;//设置模式为填充
  33. panel_view.Controls.Add(m_previewPanel);//将用户控制添加到面板中
  34. }
  35. private void textBox1_TextChanged(object sender, EventArgs e)//textbox文字更改后触发
  36. {
  37. UpdateBeamProfile();//更新表达梁的轮廓截面
  38. }
  39. private void textBox2_TextChanged(object sender, EventArgs e)//textbox文字更改后触发
  40. {
  41. UpdateBeamProfile();//更新表达梁的轮廓截面
  42. }
  43. private void textBox1_KeyPress(object sender, KeyPressEventArgs e)//在textbox输入字符时触发
  44. {
  45. if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar))//只允许输入数字与删除键
  46. {
  47. e.Handled = true;//返回成功
  48. }
  49. }
  50. private void textBox2_KeyPress(object sender, KeyPressEventArgs e)//在textbox输入字符时触发
  51. {
  52. if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar))//只允许输入数字与删除键
  53. {
  54. e.Handled = true;//返回成功
  55. }
  56. }
  57. private void button1_Click(object sender, EventArgs e)//点击button按键后触发
  58. {
  59. if (int.Parse(textBox1.Text) > 0 && int.Parse(textBox2.Text) > 0)//判断在文本框中输入的文字是否大于0
  60. {
  61. m_width = int.Parse(textBox1.Text);//将文本框中的字符串转换为int数值
  62. m_height = int.Parse(textBox2.Text);//将文本框中的字符串转换为int数值
  63. this.Close();//关闭界面
  64. Tool.BeamDrawingCommand.InstallNewInstance();//启动交互式工具
  65. }
  66. }
  67. public void UpdateBeamProfile()
  68. {
  69. if(string.IsNullOrWhiteSpace(textBox1.Text)||
  70. string.IsNullOrWhiteSpace(textBox2.Text))//判断文本框中是否为空
  71. {
  72. return;//返回
  73. }
  74. int width = int.Parse(textBox1.Text??"0");//将文本框中的值转换int数值
  75. int height = int.Parse(textBox2.Text??"0");//将文本框中的值转换int数值
  76. int textHeight = width > height ? height : width;//判断宽和高哪个长度更长
  77. Element lineElem= CreateBeamProfile(width * m_uorPerMeter, height * m_uorPerMeter);//创建用于表达梁截面的形元素
  78. Element dimensionElem1= CreateDimension(width * m_uorPerMeter, height * m_uorPerMeter, DMatrix3d.Identity, textHeight*m_uorPerMeter);//创建用于标注梁的标注元素
  79. TransformInfo transform = new TransformInfo(DTransform3d.FromTranslation(new DPoint3d(0, height * m_uorPerMeter, 0)));//声明变换信息
  80. dimensionElem1.ApplyTransform(transform);//对标注元素施加变换
  81. Element dimensionElem2 = CreateDimension(height * m_uorPerMeter, width* m_uorPerMeter, DMatrix3d.Identity, textHeight*m_uorPerMeter);//创建用于标注梁的标注元素
  82. Angle angle = new Angle();//声明角度
  83. angle.Degrees = 90;//设置角度为90度
  84. transform = new TransformInfo(DTransform3d.Rotation(DVector3d.UnitZ, angle));//初始化变换信息
  85. dimensionElem2.ApplyTransform(transform);//对标注元素施加变换
  86. transform = new TransformInfo(DTransform3d.FromTranslation(new DPoint3d(-width*m_uorPerMeter,0,0)));//初始化变换信息
  87. dimensionElem2.ApplyTransform(transform);//对标注元素施加变换
  88. IList<Element> elems =new List<Element>() { lineElem,dimensionElem1,dimensionElem2};//将标注元素与描述梁的形元素添加到列表中
  89. Element cellElem = CreateCellHeaderElement(elems);//使用列表中的元素创建单元
  90. RefreshPreview(cellElem);//刷新元素预览
  91. }
  92. private Element CreateCellHeaderElement(IList<Element> elems)
  93. {
  94. CellHeaderElement cell = new CellHeaderElement(m_dgnModel,"PreviewCell",DPoint3d.Zero,DMatrix3d.Identity,elems);//使用列表中的元素创建单元
  95. return cell;//返回单元
  96. }
  97. private Element CreateDimension(double width, double height, DMatrix3d dMatrix, double textHeight)
  98. {
  99. DPoint3d[] pos1 =
  100. {
  101. new DPoint3d(-0.5*width,-0.5*height),
  102. new DPoint3d(0.5*width,-0.5*height)
  103. };//声明用于标注的端点坐标列表
  104. DimensionElement dimension = CreateDimensionElement(pos1, dMatrix, textHeight);//创建标注元素
  105. return dimension;//返回标注元素
  106. }
  107. private Element CreateBeamProfile(double width, double height)
  108. {
  109. DPoint3d[] pos = {
  110. new DPoint3d(-0.5*width,-0.5*height),
  111. new DPoint3d(0.5*width,-0.5*height),
  112. new DPoint3d(0.5*width,0.5*height),
  113. new DPoint3d(-0.5*width,0.5*height)
  114. };//声明用于表示梁截面的形元素端点坐标列表
  115. ShapeElement shape = new ShapeElement(m_dgnModel,null, pos);//声明形元素
  116. return shape;//返回形元素
  117. }
  118. private DimensionElement CreateDimensionElement(DPoint3d[] pos, DMatrix3d dMatrix, double height)
  119. {
  120. //获取当前dgn文件中名字为"DimStyle"的标注样式,尺寸标注元素的外貌由上百个属性控制,而标注样式是一组预先设置好的属性
  121. //获取了预先订制好的标注样式之后,还可以调用DimensionStyle下的各种SetXXX成员函数修改设置的属性
  122. DimensionStyle dimStyle = new DimensionStyle("DimStyle", m_dgnFile);//声明标注样式
  123. dimStyle.SetBooleanProp(true, DimStyleProp.Placement_UseStyleAnnotationScale_BOOLINT);//设置标注样式
  124. dimStyle.SetDoubleProp(1, DimStyleProp.Placement_AnnotationScale_DOUBLE);
  125. dimStyle.SetBooleanProp(true, DimStyleProp.Text_OverrideHeight_BOOLINT);
  126. dimStyle.SetDistanceProp(0.1*height, DimStyleProp.Text_Height_DISTANCE, m_dgnModel);
  127. dimStyle.SetBooleanProp(true, DimStyleProp.Text_OverrideWidth_BOOLINT);
  128. dimStyle.SetDistanceProp(0.1 * height, DimStyleProp.Text_Width_DISTANCE, m_dgnModel);
  129. dimStyle.SetBooleanProp(true, DimStyleProp.General_UseMinLeader_BOOLINT);
  130. dimStyle.SetDoubleProp(0.01, DimStyleProp.Terminator_MinLeader_DOUBLE);
  131. dimStyle.SetBooleanProp(true, DimStyleProp.Value_AngleMeasure_BOOLINT);
  132. dimStyle.SetAccuracyProp((byte)AnglePrecision.Use1Place, DimStyleProp.Value_AnglePrecision_INTEGER);
  133. int alignInt = (int)DimStyleProp_General_Alignment.True;
  134. StatusInt status = dimStyle.SetIntegerProp(alignInt, DimStyleProp.General_Alignment_INTEGER);
  135. dimStyle.GetIntegerProp(out int valueOut, DimStyleProp.General_Alignment_INTEGER);
  136. DgnTextStyle textStyle = new DgnTextStyle("TestStyle", m_dgnFile);//设置文字样式
  137. LevelId lvlId = Settings.GetLevelIdFromName("Default");//设置图层
  138. CreateDimensionCallbacks callbacks = new CreateDimensionCallbacks(dimStyle, textStyle, new Symbology(), lvlId, null);//尺寸标注元素的构造函数会调用DimensionCreateData的各个成员函数去获取声明尺寸标注元素需要的各种参数
  139. DimensionElement dimEle = new DimensionElement(m_dgnModel, callbacks, DimensionType.SizeStroke);//声明标注元素
  140. if (dimEle.IsValid)//判断标注元素是否有效
  141. {
  142. for (int i = 0; i < pos.Count(); i++)
  143. {
  144. dimEle.InsertPoint(pos[i], null, dimStyle, -1);//对标注元素设置插入点
  145. }
  146. dimEle.SetHeight(0.1 * height);//设置尺寸标注元素的高度
  147. dimEle.SetRotationMatrix(dMatrix);//设置变换信息
  148. }
  149. return dimEle;
  150. }
  151. private void RefreshPreview(Element elem)
  152. {
  153. m_previewPanel.ShowPreview(elem);//预览元素
  154. }
  155. }
  156. class CreateDimensionCallbacks : DimensionCreateData
  157. {
  158. private DimensionStyle m_dimStyle;
  159. private DgnTextStyle m_textStyle;
  160. private Symbology m_symbology;
  161. private LevelId m_levelId;
  162. private DirectionFormatter m_directionFormatter;
  163. public CreateDimensionCallbacks(DimensionStyle dimStyle, DgnTextStyle textStyle, Symbology symb, LevelId levelId, DirectionFormatter formatter)
  164. {
  165. m_dimStyle = dimStyle;
  166. m_textStyle = textStyle;
  167. m_symbology = symb;
  168. m_levelId = levelId;
  169. m_directionFormatter = formatter;
  170. }
  171. public override DimensionStyle GetDimensionStyle()
  172. {
  173. return m_dimStyle;
  174. }
  175. public override DgnTextStyle GetTextStyle()
  176. {
  177. return m_textStyle;
  178. }
  179. public override Symbology GetSymbology()
  180. {
  181. return m_symbology;
  182. }
  183. public override LevelId GetLevelId()
  184. {
  185. return m_levelId;
  186. }
  187. public override int GetViewNumber()
  188. {
  189. return 0;
  190. }
  191. //此函数返回的旋转矩阵与GetViewRotation返回的旋转矩阵共同声明了尺寸标注元素的方向
  192. public override DMatrix3d GetDimensionRotation()
  193. {
  194. return DMatrix3d.Identity;
  195. }
  196. public override DMatrix3d GetViewRotation()
  197. {
  198. return DMatrix3d.Identity;
  199. }
  200. //用于从数字方向值构造字符串。
  201. public override DirectionFormatter GetDirectionFormatter()
  202. {
  203. return m_directionFormatter;
  204. }
  205. }
  206. }
  1. namespace WinformUIIntroduction.UI
  2. {
  3. partial class BeamCreateMenu
  4. {
  5. /// <summary>
  6. /// Required designer variable.
  7. /// </summary>
  8. private System.ComponentModel.IContainer components = null;
  9. /// <summary>
  10. /// Clean up any resources being used.
  11. /// </summary>
  12. /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  13. protected override void Dispose(bool disposing)
  14. {
  15. if (disposing && (components != null))
  16. {
  17. components.Dispose();
  18. }
  19. base.Dispose(disposing);
  20. }
  21. #region Windows Form Designer generated code
  22. /// <summary>
  23. /// Required method for Designer support - do not modify
  24. /// the contents of this method with the code editor.
  25. /// </summary>
  26. private void InitializeComponent()
  27. {
  28. this.panel_view = new System.Windows.Forms.Panel();
  29. this.label1 = new System.Windows.Forms.Label();
  30. this.label2 = new System.Windows.Forms.Label();
  31. this.textBox1 = new System.Windows.Forms.TextBox();
  32. this.textBox2 = new System.Windows.Forms.TextBox();
  33. this.button1 = new System.Windows.Forms.Button();
  34. this.SuspendLayout();
  35. //
  36. // panel_view
  37. //
  38. this.panel_view.Location = new System.Drawing.Point(168, 12);
  39. this.panel_view.Name = "panel_view";
  40. this.panel_view.Size = new System.Drawing.Size(217, 237);
  41. this.panel_view.TabIndex = 0;
  42. //
  43. // label1
  44. //
  45. this.label1.AutoSize = true;
  46. this.label1.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  47. this.label1.Location = new System.Drawing.Point(12, 25);
  48. this.label1.Name = "label1";
  49. this.label1.Size = new System.Drawing.Size(32, 17);
  50. this.label1.TabIndex = 0;
  51. this.label1.Text = "梁宽";
  52. //
  53. // label2
  54. //
  55. this.label2.AutoSize = true;
  56. this.label2.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  57. this.label2.Location = new System.Drawing.Point(12, 50);
  58. this.label2.Name = "label2";
  59. this.label2.Size = new System.Drawing.Size(32, 17);
  60. this.label2.TabIndex = 1;
  61. this.label2.Text = "梁高";
  62. //
  63. // textBox1
  64. //
  65. this.textBox1.Location = new System.Drawing.Point(62, 22);
  66. this.textBox1.Name = "textBox1";
  67. this.textBox1.Size = new System.Drawing.Size(100, 20);
  68. this.textBox1.TabIndex = 0;
  69. this.textBox1.Text = "300";
  70. this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
  71. this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress);
  72. //
  73. // textBox2
  74. //
  75. this.textBox2.Location = new System.Drawing.Point(62, 47);
  76. this.textBox2.Name = "textBox2";
  77. this.textBox2.Size = new System.Drawing.Size(100, 20);
  78. this.textBox2.TabIndex = 2;
  79. this.textBox2.Text = "500";
  80. this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged);
  81. this.textBox2.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox2_KeyPress);
  82. //
  83. // button1
  84. //
  85. this.button1.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  86. this.button1.Location = new System.Drawing.Point(41, 210);
  87. this.button1.Name = "button1";
  88. this.button1.Size = new System.Drawing.Size(75, 23);
  89. this.button1.TabIndex = 3;
  90. this.button1.Text = "确认";
  91. this.button1.UseVisualStyleBackColor = true;
  92. this.button1.Click += new System.EventHandler(this.button1_Click);
  93. //
  94. // BeamCreateMenu
  95. //
  96. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
  97. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  98. this.ClientSize = new System.Drawing.Size(397, 261);
  99. this.Controls.Add(this.button1);
  100. this.Controls.Add(this.textBox2);
  101. this.Controls.Add(this.textBox1);
  102. this.Controls.Add(this.label2);
  103. this.Controls.Add(this.label1);
  104. this.Controls.Add(this.panel_view);
  105. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
  106. this.MaximizeBox = false;
  107. this.Name = "BeamCreateMenu";
  108. this.ShowIcon = false;
  109. this.Text = "BeamCreateMenu";
  110. this.TopMost = true;
  111. this.ResumeLayout(false);
  112. this.PerformLayout();
  113. }
  114. #endregion
  115. private System.Windows.Forms.Panel panel_view;
  116. private System.Windows.Forms.Label label1;
  117. private System.Windows.Forms.Label label2;
  118. private System.Windows.Forms.TextBox textBox1;
  119. private System.Windows.Forms.TextBox textBox2;
  120. private System.Windows.Forms.Button button1;
  121. }
  122. }
  1. extern alias dgnDisplayAlias;
  2. using System.Windows.Forms;
  3. using System.Windows.Forms.Integration;
  4. using dgnDisplayAlias::Bentley.DgnPlatform;
  5. namespace WinformUIIntroduction.UI
  6. {
  7. public partial class PreviewPanel : UserControl
  8. {
  9. private readonly dgnDisplayAlias::Bentley.DgnPlatform.PreviewControl mPreviewControl;
  10. public PreviewPanel(Bentley.DgnPlatformNET.DgnModelRef modelRef)
  11. {
  12. InitializeComponent();
  13. unsafe
  14. {
  15. this.mPreviewControl =
  16. new dgnDisplayAlias::Bentley.DgnPlatform.PreviewControl(
  17. (dgnDisplayAlias::Bentley.DgnPlatform.DgnModel*)modelRef.GetDgnModel().GetNative());
  18. }
  19. this.mPreviewControl.ActivatePanTool();
  20. this.mPreviewControl.PreviewControlOptions.IsFitToolVisible = true;
  21. this.mPreviewControl.PreviewControlOptions.IsPanToolVisible = true;
  22. this.mPreviewControl.PreviewControlOptions.IsViewingToolsVisible = true;
  23. this.mPreviewControl.PreviewControlOptions.IsZoomToolsVisible = true;
  24. this.mPreviewControl.PreviewControlOptions.IsRotationToolVisible = true;
  25. this.mPreviewControl.IsEnabled = true;
  26. this.mPreviewControl.IsManipulationEnabled = true;
  27. this.mPreviewControl.PreviewControlOptions.RotationMode = RotationMode.Top;
  28. this.mPreviewControl.PreviewControlOptions.RenderMode = RenderMode.FilledVisibleEdge;
  29. ElementHost elementHost = new ElementHost();
  30. elementHost.Dock = DockStyle.Fill;
  31. elementHost.Child = this.mPreviewControl;
  32. this.Controls.Add(elementHost);
  33. }
  34. public void ShowPreview(Bentley.DgnPlatformNET.Elements.Element ele)
  35. {
  36. Bentley.DgnPlatformNET.ElementAgenda agenda = new Bentley.DgnPlatformNET.ElementAgenda();
  37. if (ele != null)
  38. {
  39. agenda.Insert(ele, true);
  40. }
  41. this.mPreviewControl.ShowPreview(agenda);
  42. }
  43. }
  44. }
  1. using Bentley.DgnPlatformNET;
  2. using Bentley.DgnPlatformNET.Elements;
  3. using Bentley.GeometryNET;
  4. using Bentley.MstnPlatformNET;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace WinformUIIntroduction.Tool
  11. {
  12. class BeamDrawingCommand : DgnElementSetTool
  13. {
  14. private List<DPoint3d> m_pos;//声明坐标列表
  15. private DgnModel m_dgnModel;//声明模型空间
  16. private double m_uorPerMilliMeter;//声明单位分辨率与毫米的比值
  17. public BeamDrawingCommand(int toolId, int prompt) : base(toolId, prompt)//继承基类的构造函数
  18. {
  19. }
  20. public static void InstallNewInstance()//该命令的入口函数
  21. {
  22. BeamDrawingCommand primitiveTool = new BeamDrawingCommand(0, 0);//创建实例
  23. primitiveTool.InstallTool();//加载工具
  24. }
  25. /*
  26. * 如果我们对通过参数传递进来的元素进行修改,并且返回SUCCESS的话,在_DoOperationForModify
  27. * 中会用修改后的元素替换掉原来的元素,当然前提是_IsModifyOriginal返回true。否则的话会直接
  28. * 把修改后的元素重新添加到Dgn文件中。
  29. */
  30. public override StatusInt OnElementModify(Element element)
  31. {
  32. return StatusInt.Error;
  33. }
  34. protected override void OnRestartTool()//重启工具时触发
  35. {
  36. }
  37. protected override void OnPostInstall()//工具激活后执行
  38. {
  39. m_dgnModel = Session.Instance.GetActiveDgnModel();//获得当前激活的模型
  40. m_uorPerMilliMeter = Session.Instance.GetActiveDgnModel().GetModelInfo().UorPerMeter/1000;//分辨率单位转换为毫米
  41. m_pos = new List<DPoint3d>();//初始化列表
  42. }
  43. protected override bool OnDataButton(DgnButtonEvent ev)//点击确认键(默认为左键)后触发
  44. {
  45. if(m_pos.Count() == 0)//判断列表中的坐标点个数
  46. {
  47. m_pos.Add(ev.Point);//将坐标值添加到列表中
  48. BeginDynamics();//启动动态绘制
  49. return true;//返回
  50. }
  51. else
  52. {
  53. EndDynamics();//关闭动态绘制
  54. m_pos.Add(ev.Point);//将坐标值添加到列表中
  55. CreateBeamElem();//创建构建梁的元素
  56. m_pos.Clear();//清空列表
  57. return true;//返回
  58. }
  59. }
  60. protected override bool OnResetButton(DgnButtonEvent ev)//点击重置键(默认为右键)触发
  61. {
  62. if(m_pos.Count()==0)//判断列表中坐标点个数是否为零
  63. {
  64. ExitTool();//退出工具
  65. }
  66. else
  67. {
  68. EndDynamics();//关闭动态绘制
  69. m_pos.Clear();//清空列表
  70. }
  71. return true;
  72. }
  73. protected override void OnDynamicFrame(DgnButtonEvent ev)//动态绘制时触发
  74. {
  75. ShapeElement m_beamProfile = CreateBeamProfile(m_pos[0]);//创建形元素用于确定梁截面
  76. Element element = CreateSolidElement(m_pos[0], ev.Point,m_beamProfile);//创建梁实体元素
  77. if (null == element)//若未成功生成梁实体元素
  78. return;//返回
  79. DynamicDrawElems(element);//动态绘制元素
  80. }
  81. private ShapeElement CreateBeamProfile(DPoint3d startPo)//创建用于表达梁截面的形元素
  82. {
  83. DPoint3d[] pos =
  84. {
  85. new DPoint3d(startPo.X-0.5*UI.BeamCreateMenu.m_width*m_uorPerMilliMeter,startPo.Y,startPo.Z),
  86. new DPoint3d(startPo.X-0.5*UI.BeamCreateMenu.m_width*m_uorPerMilliMeter,startPo.Y,startPo.Z-1*UI.BeamCreateMenu.m_height*m_uorPerMilliMeter),
  87. new DPoint3d(startPo.X+0.5*UI.BeamCreateMenu.m_width*m_uorPerMilliMeter,startPo.Y,startPo.Z-1*UI.BeamCreateMenu.m_height*m_uorPerMilliMeter),
  88. new DPoint3d(startPo.X+0.5*UI.BeamCreateMenu.m_width*m_uorPerMilliMeter,startPo.Y,startPo.Z)
  89. };//确定梁截面端点坐标集
  90. ShapeElement beamProfile = new ShapeElement(m_dgnModel,null,pos);//创建表达梁截面的形元素
  91. return beamProfile;//返回梁截面的形元素
  92. }
  93. private void DynamicDrawElems(Element element)
  94. {
  95. RedrawElems redrawElems = new RedrawElems();//使用元素用于动态绘制
  96. redrawElems.SetDynamicsViewsFromActiveViewSet(Session.GetActiveViewport());//设置视角
  97. redrawElems.DrawMode = DgnDrawMode.TempDraw;//设置绘制模式
  98. redrawElems.DrawPurpose = DrawPurpose.Dynamics;//设置绘制目标
  99. redrawElems.DoRedraw(element);//使用元素用于动态绘制
  100. }
  101. private Element CreateSolidElement(DPoint3d startPo, DPoint3d endPo, ShapeElement beamProfile)
  102. {
  103. DVector3d vector = new DVector3d(startPo, endPo);//声明梁方向向量
  104. if (vector == DVector3d.Zero)//判断是否成功获取
  105. {
  106. return null;//返回空
  107. }
  108. TransformInfo trans = new TransformInfo(DTransform3d.FromRotationAroundLine(startPo, DVector3d.UnitZ, vector.Rotate90CCWXY().AngleXY));//声明变换信息
  109. beamProfile.ApplyTransform(trans);//对形元素施加变换
  110. Element solid = SolidElement.CreateProjectionElement(m_dgnModel, null, beamProfile, startPo, vector, DTransform3d.Identity, true);//创建拉伸实体
  111. return solid;//返回拉伸实体
  112. }
  113. private void CreateBeamElem()
  114. {
  115. ShapeElement beamProfile= CreateBeamProfile(m_pos[0]);//创建表达梁截面的形元素
  116. Element element = CreateSolidElement(m_pos[0], m_pos[1], beamProfile);//创建拉伸元素
  117. element.AddToModel();//将拉伸元素写入模型
  118. }
  119. }
  120. }

1.gif
图52 可视化矩形梁生成工具

EC属性赋值工具

  1. 该工具会根据用户输入的路径获取Schema文件的路径,然后通过路径读取对应的Schema文件并在树状图中显示EC类,当用户选择树状图上的节点时,此时会触发事件,根据EC属性添加用户自定义控件用于显示EC属性并可对其进行赋值操作。完成后选取元素,点击界面上的应用,此时元素会被赋予指定EC类,同时修改的EC属性值也会被同步赋予。<br /> 该工具涉及到的WinForm控件有:TextBoxButtonTreeViewPanelUserControl(用户自定义控件)。<br />![image.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646991105225-7d2718bf-cef6-4deb-bb81-bea7abaee77a.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=276&id=u6091fd32&margin=%5Bobject%20Object%5D&name=image.png&originHeight=276&originWidth=1507&originalType=binary&ratio=1&rotation=0&showTitle=false&size=16612&status=done&style=none&taskId=u5e6f1780-452f-4d75-92e9-305b85a7c20&title=&width=1507)<br />**图53 工具流程图**<br />![image.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646991142159-534db121-9b96-4026-826b-928de465cc9f.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=215&id=u8073ebb5&margin=%5Bobject%20Object%5D&name=image.png&originHeight=215&originWidth=1496&originalType=binary&ratio=1&rotation=0&showTitle=false&size=19128&status=done&style=none&taskId=u45256893-d195-433a-8483-681fb7b6833&title=&width=1496)<br />**图54 控件调用流程图**
  1. using Bentley.DgnPlatformNET;
  2. using Bentley.DgnPlatformNET.DgnEC;
  3. using Bentley.DgnPlatformNET.Elements;
  4. using Bentley.ECObjects.Instance;
  5. using Bentley.ECObjects.Schema;
  6. using Bentley.ECObjects.XML;
  7. using Bentley.MstnPlatformNET;
  8. using Bentley.MstnPlatformNET.WinForms;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.ComponentModel;
  12. using System.Data;
  13. using System.Drawing;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. using System.Windows.Forms;
  18. using System.Xml;
  19. namespace WinformUIIntroduction.UI
  20. {
  21. public partial class ECAttachMenu :Adapter// Form//
  22. {
  23. private DgnFile m_dgnFile;//声明文件
  24. public IECSchema m_ecschema;//声明需要导入的ECSchema
  25. public ECAttachMenu()
  26. {
  27. InitializeComponent();//初始化界面
  28. m_dgnFile = Session.Instance.GetActiveDgnFile();//获得当前的文件
  29. }
  30. private void button1_Click(object sender, EventArgs e)//点击button按键后触发
  31. {
  32. m_treeView_ECClass.Nodes.Clear();//清空树状图节点信息
  33. SelectSchemaFilePath();//选择Schema文件路径
  34. if(string.IsNullOrWhiteSpace(this.m_textBox_import.Text))//判断文字框中文字是否为空
  35. {
  36. return;//返回
  37. }
  38. LoadSchemaData();//读取Schema文件信息
  39. CreateTreeView();//创建树状视图
  40. }
  41. private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)//点击树状图节点时触发
  42. {
  43. AddECPropItems(e);//在用户控件界面添加EC属性框
  44. }
  45. private void button2_Click(object sender, EventArgs e)//点击button按键后触发
  46. {
  47. if(m_treeView_ECClass.SelectedNode!=null)//判断树状图节点是否被成功选取
  48. {
  49. UpdateSchemaData();//更新Schema数据
  50. }
  51. }
  52. private void UpdateSchemaData()
  53. {
  54. IECClass ecClass = m_ecschema.GetClass(m_treeView_ECClass.SelectedNode.Text);//获得指定名称的EC类
  55. DgnECInstanceEnabler instanceEnabler = DgnECManager.Manager.ObtainInstanceEnabler(m_dgnFile, ecClass);//获得EC实例启动器
  56. ElementAgenda agenda = new ElementAgenda();//声明元素容器
  57. SelectionSetManager.BuildAgenda(ref agenda);//从当前选择集中获得元素
  58. for (uint i=0;i<agenda.GetCount();i++)//对选择集中的元素进行遍历
  59. {
  60. IDgnECInstance instance = instanceEnabler.CreateInstanceOnElement(agenda.GetEntry(i), instanceEnabler.SharedWipInstance, false);//在元素上创建EC实例
  61. foreach (ECItem item in m_proppanel_ECProp.Controls)//获得界面中用户控件集
  62. {
  63. if (!string.IsNullOrWhiteSpace(item.textBox1.Text))//判断文本框中文字是否为空或空白
  64. {
  65. instance.SetString(item.label1.Text, item.textBox1.Text);//设置属性值
  66. }
  67. }
  68. instance.WriteChanges();//更新文件上的EC实例
  69. }
  70. }
  71. private void AddECPropItems(TreeNodeMouseClickEventArgs e)
  72. {
  73. m_proppanel_ECProp.Controls.Clear();//清空面板中的用户控件
  74. IECClass eCs = m_ecschema.GetClass(e.Node.Name);//使用树状图中的节点名称从ECSchema中获取EC类
  75. IEnumerable<IECProperty> props = eCs.Properties(true);//获得EC类中的EC属性
  76. int j = 0;//声明int值用于控制用户控件的间距
  77. foreach (IECProperty prop in props)//遍历EC类中的EC属性
  78. {
  79. ECItem item = new ECItem();//声明用于显示EC属性及值的用户控件
  80. item.label1.Text = prop.Name;//设置用户控件中的标签名称为EC属性名称
  81. item.textBox1.Tag = prop.Type.Name;//设置用户控件中的文本框的标签为EC属性类型
  82. switch (prop.Type.Name)//选择EC属性值
  83. {
  84. case "int"://若EC属性为int值
  85. break;//跳出
  86. case "string"://若EC属性为string值
  87. break;//跳出
  88. default://其余情况
  89. item.textBox1.Enabled = false;//锁定文本框,不允许用户输入数据
  90. break;//跳出
  91. }
  92. item.Top = 28 * j;//设置用户控件位置
  93. item.Parent = m_proppanel_ECProp;//确定控件依赖的面板
  94. j++;//增加int值
  95. }
  96. m_proppanel_ECProp.AutoScroll = true;//启动面板自动滚动
  97. m_proppanel_ECProp.Show();//显示面板
  98. }
  99. private void CreateTreeView()
  100. {
  101. IECClass[]classes= m_ecschema.GetClasses();//获得ECSchema中的所有EC类
  102. for(int i=0;i<classes.Count();i++)//遍历EC类
  103. {
  104. TreeNode ti = new TreeNode();//创建树状图节点
  105. ti.Name = classes[i].Name;//设置树状图节点的名称的EC类名
  106. ti.Text = classes[i].Name;//设置树状图节点的文字的EC类名
  107. m_treeView_ECClass.Nodes.Add(ti);//在树状图中添加节点
  108. }
  109. m_treeView_ECClass.ExpandAll();//展开树状图
  110. }
  111. private void SelectSchemaFilePath()
  112. {
  113. OpenFileDialog dialog = new OpenFileDialog();//声明文件对话框
  114. dialog.Filter = "*.ecschema.xml|*.ecschema.XML";//设置文件选取过滤器为识别后缀.ecschema.xml的文件
  115. dialog.FilterIndex = 1;//设置过滤器索引
  116. if (dialog.ShowDialog() == DialogResult.OK)//判断是否成功输入
  117. {
  118. this.m_textBox_import.Text = dialog.FileName;//设置文本框中的文字为文件路径
  119. }
  120. }
  121. private void LoadSchemaData()
  122. {
  123. XmlDocument xmldoc = new XmlDocument();//声明XML文件浏览器
  124. xmldoc.Load(m_textBox_import.Text);//读取指定路径的xml文件
  125. string xmlStr = xmldoc.InnerXml;//获得读取到的文字内容
  126. ECSchemaXmlStringReader xmlReader = new ECSchemaXmlStringReader(xmlStr);//声明ECSchema阅读器
  127. m_ecschema = xmlReader.Deserialize();//将EC Schema阅读器读取到的信息反序列化
  128. if (null == m_ecschema)//判断是否成功获得ECSchema
  129. {
  130. MessageBox.Show("Schema not found, please check");//对话框输出未获得指定ECSchema
  131. return;//返回
  132. }
  133. ImportSchemaOptions options = new ImportSchemaOptions();//声明导入Schema选项
  134. DgnECManager.Manager.ImportSchema(m_ecschema, m_dgnFile, options);//导入ECSchema
  135. return;//返回
  136. }
  137. }
  138. }
  1. namespace WinformUIIntroduction.UI
  2. {
  3. partial class ECAttachMenu
  4. {
  5. /// <summary>
  6. /// Required designer variable.
  7. /// </summary>
  8. private System.ComponentModel.IContainer components = null;
  9. /// <summary>
  10. /// Clean up any resources being used.
  11. /// </summary>
  12. /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  13. protected override void Dispose(bool disposing)
  14. {
  15. if (disposing && (components != null))
  16. {
  17. components.Dispose();
  18. }
  19. base.Dispose(disposing);
  20. }
  21. #region Windows Form Designer generated code
  22. /// <summary>
  23. /// Required method for Designer support - do not modify
  24. /// the contents of this method with the code editor.
  25. /// </summary>
  26. private void InitializeComponent()
  27. {
  28. this.m_treeView_ECClass = new System.Windows.Forms.TreeView();
  29. this.m_button_import = new System.Windows.Forms.Button();
  30. this.m_button_apply = new System.Windows.Forms.Button();
  31. this.m_textBox_import = new System.Windows.Forms.TextBox();
  32. this.m_proppanel_ECProp = new System.Windows.Forms.Panel();
  33. this.SuspendLayout();
  34. //
  35. // m_treeView_ECClass
  36. //
  37. this.m_treeView_ECClass.HideSelection = false;
  38. this.m_treeView_ECClass.Location = new System.Drawing.Point(12, 42);
  39. this.m_treeView_ECClass.Name = "m_treeView_ECClass";
  40. this.m_treeView_ECClass.Size = new System.Drawing.Size(169, 235);
  41. this.m_treeView_ECClass.TabIndex = 0;
  42. this.m_treeView_ECClass.NodeMouseClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.treeView1_NodeMouseClick);
  43. //
  44. // m_button_import
  45. //
  46. this.m_button_import.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  47. this.m_button_import.Location = new System.Drawing.Point(448, 11);
  48. this.m_button_import.Name = "m_button_import";
  49. this.m_button_import.Size = new System.Drawing.Size(75, 23);
  50. this.m_button_import.TabIndex = 1;
  51. this.m_button_import.Text = "导入";
  52. this.m_button_import.UseVisualStyleBackColor = true;
  53. this.m_button_import.Click += new System.EventHandler(this.button1_Click);
  54. //
  55. // m_button_apply
  56. //
  57. this.m_button_apply.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  58. this.m_button_apply.Location = new System.Drawing.Point(319, 254);
  59. this.m_button_apply.Name = "m_button_apply";
  60. this.m_button_apply.Size = new System.Drawing.Size(75, 23);
  61. this.m_button_apply.TabIndex = 2;
  62. this.m_button_apply.Text = "应用";
  63. this.m_button_apply.UseVisualStyleBackColor = true;
  64. this.m_button_apply.Click += new System.EventHandler(this.button2_Click);
  65. //
  66. // m_textBox_import
  67. //
  68. this.m_textBox_import.Location = new System.Drawing.Point(12, 14);
  69. this.m_textBox_import.Name = "m_textBox_import";
  70. this.m_textBox_import.ReadOnly = true;
  71. this.m_textBox_import.Size = new System.Drawing.Size(430, 20);
  72. this.m_textBox_import.TabIndex = 3;
  73. //
  74. // m_proppanel_ECProp
  75. //
  76. this.m_proppanel_ECProp.Location = new System.Drawing.Point(187, 42);
  77. this.m_proppanel_ECProp.Name = "m_proppanel_ECProp";
  78. this.m_proppanel_ECProp.Size = new System.Drawing.Size(336, 206);
  79. this.m_proppanel_ECProp.TabIndex = 4;
  80. //
  81. // ECAttachMenu
  82. //
  83. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
  84. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  85. this.ClientSize = new System.Drawing.Size(538, 289);
  86. this.Controls.Add(this.m_proppanel_ECProp);
  87. this.Controls.Add(this.m_textBox_import);
  88. this.Controls.Add(this.m_button_apply);
  89. this.Controls.Add(this.m_button_import);
  90. this.Controls.Add(this.m_treeView_ECClass);
  91. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
  92. this.MaximizeBox = false;
  93. this.Name = "ECAttachMenu";
  94. this.ShowIcon = false;
  95. this.Text = "ECAttachTool";
  96. this.TopMost = true;
  97. this.ResumeLayout(false);
  98. this.PerformLayout();
  99. }
  100. #endregion
  101. private System.Windows.Forms.TreeView m_treeView_ECClass;
  102. private System.Windows.Forms.Button m_button_import;
  103. private System.Windows.Forms.Button m_button_apply;
  104. private System.Windows.Forms.TextBox m_textBox_import;
  105. private System.Windows.Forms.Panel m_proppanel_ECProp;
  106. }
  107. }
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace WinformUIIntroduction.UI
  11. {
  12. public partial class ECItem : UserControl
  13. {
  14. public ECItem()
  15. {
  16. InitializeComponent();
  17. }
  18. private void textBox1_KeyPress(object sender, KeyPressEventArgs e)//在文本框中点击按键时触发
  19. {
  20. switch (textBox1.Tag)//根据文本框的标签进行设置
  21. {
  22. case "int"://当文本框的标签设置为"int"时
  23. if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar))//只允许在文本框中输入数组与回退
  24. {
  25. e.Handled = true;//返回真
  26. }
  27. break;//跳出
  28. case "string"://当文本框的标签设置为"string"时
  29. break;//跳出
  30. }
  31. }
  32. }
  33. }

2.gif
图55 EC属性赋值工具

文件选择复制工具

  1. 该工具会根据用户选择获得需要赋值元素的文件,读取文件信息后根据用户选择的模型动态读取模型中的元素信息,并实时调整条件筛选多选框中元素类型,元素图层,ItemType信息等,同时根据多选框中的设置动态锁定/解锁下拉框,用机制保证就算用户没有使用该工具的经验,只要根据插件给出的信息即可直接上手。最后点击执行后,程序会根据当前的筛选条件动态赋值模型中的元素,同时当RadioButton选中的是输出生成信息时,输出复制结果。并且在复制过程中,使用ProgressBar显示复制进程。<br /> 该工具涉及到的WinForm控件有:TextBoxButtonComboBoxListBoxRadioButtonLabelCheckBoxProgressBar。<br />![image.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646991599980-d384617c-fc1d-4289-ad8b-a23c2043c0ad.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=258&id=ub61e7311&margin=%5Bobject%20Object%5D&name=image.png&originHeight=258&originWidth=1493&originalType=binary&ratio=1&rotation=0&showTitle=false&size=17956&status=done&style=none&taskId=u9c22cb40-77fd-47fc-8862-5192e35c3e0&title=&width=1493)<br />**图56 工具流程图**<br />![image.png](https://cdn.nlark.com/yuque/0/2022/png/21640708/1646991647112-59bce980-d2e1-44d0-9e15-34e303f45768.png#clientId=ued29b667-f53d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=354&id=u1d3dee86&margin=%5Bobject%20Object%5D&name=image.png&originHeight=354&originWidth=1466&originalType=binary&ratio=1&rotation=0&showTitle=false&size=48238&status=done&style=none&taskId=ua9de7587-d755-4886-9fb0-520878393d0&title=&width=1466)<br />**图57 控件调用流程图**
  1. using Bentley.DgnPlatformNET;
  2. using Bentley.DgnPlatformNET.DgnEC;
  3. using Bentley.DgnPlatformNET.Elements;
  4. using Bentley.GeometryNET;
  5. using Bentley.MstnPlatformNET;
  6. using Bentley.MstnPlatformNET.WinForms;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.ComponentModel;
  10. using System.Data;
  11. using System.Drawing;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows.Forms;
  16. namespace WinformUIIntroduction.UI
  17. {
  18. public partial class FilterCopyMenu : Adapter// Form//
  19. {
  20. private DgnFile m_dgnFile;//声明文件
  21. private DgnModel m_dgnModel;//声明模型
  22. private List<Element> m_elems;//声明用于储存元素的列表
  23. private List<Element> m_selectedElems;//声明用于储存选取元素的列表
  24. public FilterCopyMenu()//界面的构造函数
  25. {
  26. InitializeComponent();//初始化界面
  27. m_dgnModel = Session.Instance.GetActiveDgnModel();//初始化模型为当前的模型空间
  28. m_radioButton_outputinfo.Select();//设置默认单选选中状态
  29. m_elems = new List<Element>();//初始化列表
  30. m_selectedElems = new List<Element>();//初始化列表
  31. }
  32. private void button2_Click(object sender, EventArgs e)//点击button按键后触发
  33. {
  34. SelectSchemaFilePath();//输入Schema文件地址路径
  35. }
  36. private void m_textbox_modelname_TextChanged(object sender, EventArgs e)//textbox文字更改后触发
  37. {
  38. if (!ReadDgnFile())//判断是否成功读取到文件
  39. {
  40. return;//返回
  41. }
  42. DisplayDgnModelNames();//在下拉框中显示模型名称
  43. }
  44. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)//下拉框选择索引值变化时触发
  45. {
  46. if (string.IsNullOrWhiteSpace(m_comboBox_importmodel.Text))//判断下拉框中文字是否为空
  47. {
  48. return;//返回
  49. }
  50. m_checkBox_checkall.Enabled = true;//启用复选框
  51. m_checkBox_type.Enabled = true;
  52. m_checkBox_level.Enabled = true;
  53. m_checkBox_color.Enabled = true;
  54. m_checkBox_itemtype.Enabled = true;
  55. m_radioButton_outputinfo.Enabled = true;//启用单选选项
  56. m_radioButton_nooutputinfo.Enabled = true;
  57. m_comboBox_type.Items.Clear();//清空下拉框中的数据
  58. m_comboBox_level.Items.Clear();
  59. m_comboBox_color.Items.Clear();
  60. m_comboBox_itemtype.Items.Clear();
  61. m_checkBox_checkall.Checked = false;//设置复选框为未选择状态
  62. m_checkBox_type.Checked = false;
  63. m_checkBox_level.Checked = false;
  64. m_checkBox_color.Checked = false;
  65. m_checkBox_itemtype.Checked = false;
  66. m_label_elemscount.Text = 0.ToString();//设置用于计算总数
  67. m_button_execute.Enabled = true;//启动按钮
  68. GetGraphicElems();//获得当前模型中的图形元素集
  69. FilterSelectedElems();//根据当前过滤条件筛选元素
  70. }
  71. private void checkBox1_CheckedChanged(object sender, EventArgs e)//复选框勾选时触发
  72. {
  73. if(m_checkBox_checkall.CheckState==CheckState.Checked)//判断复选框是否被勾选
  74. {
  75. m_checkBox_type.CheckState = CheckState.Checked;//设置该复选框为勾选状态
  76. m_checkBox_level.CheckState = CheckState.Checked;
  77. m_checkBox_color.CheckState = CheckState.Checked;
  78. m_checkBox_itemtype.CheckState = CheckState.Checked;
  79. }
  80. else if(m_checkBox_checkall.CheckState==CheckState.Unchecked)//判断复选框是否未被勾选
  81. {
  82. m_checkBox_type.CheckState = CheckState.Unchecked;//设置该复选框为未勾选状态
  83. m_checkBox_level.CheckState = CheckState.Unchecked;
  84. m_checkBox_color.CheckState = CheckState.Unchecked;
  85. m_checkBox_itemtype.CheckState = CheckState.Unchecked;
  86. }
  87. }
  88. private void checkBox2_CheckedChanged(object sender, EventArgs e)//复选框勾选时触发
  89. {
  90. if (m_checkBox_type.CheckState == CheckState.Checked)//判断复选框是否被勾选
  91. {
  92. m_comboBox_type.Enabled = true;//启动下拉框
  93. ShowElemTypeItems();//显示元素类型
  94. }
  95. else if (m_checkBox_type.CheckState == CheckState.Unchecked)//判断复选框是否未被勾选
  96. {
  97. m_comboBox_type.Enabled = false;//锁定下拉框
  98. FilterSelectedElems();//根据当前过滤条件筛选元素
  99. }
  100. }
  101. private void checkBox3_CheckedChanged(object sender, EventArgs e)//复选框勾选时触发
  102. {
  103. if (m_checkBox_level.CheckState == CheckState.Checked)//判断复选框是否被勾选
  104. {
  105. m_comboBox_level.Enabled = true;//启动下拉框
  106. ShowLevelItems();//显示元素图层
  107. }
  108. else if (m_checkBox_level.CheckState == CheckState.Unchecked)//判断复选框是否未被勾选
  109. {
  110. m_comboBox_level.Enabled = false;//锁定下拉框
  111. FilterSelectedElems();//根据当前过滤条件筛选元素
  112. }
  113. }
  114. private void checkBox4_CheckedChanged(object sender, EventArgs e)//复选框勾选时触发
  115. {
  116. if (m_checkBox_color.CheckState == CheckState.Checked)//判断复选框是否被勾选
  117. {
  118. m_comboBox_color.Enabled = true;//启动下拉框
  119. ShowColorIndexes();//显示颜色索引
  120. }
  121. else if (m_checkBox_color.CheckState == CheckState.Unchecked)//判断复选框是否未被勾选
  122. {
  123. m_comboBox_color.Enabled = false;//锁定下拉框
  124. FilterSelectedElems();//根据当前过滤条件筛选元素
  125. }
  126. }
  127. private void checkBox5_CheckedChanged(object sender, EventArgs e)//复选框勾选时触发
  128. {
  129. if (m_checkBox_itemtype.CheckState == CheckState.Checked)//判断复选框是否被勾选
  130. {
  131. m_comboBox_itemtype.Enabled = true;//启动下拉框
  132. m_listBox_itemtype.Enabled = true;//启动列表框
  133. ShowItemTypesInComboBox();//在下拉框中显示ItemType
  134. }
  135. else if (m_checkBox_itemtype.CheckState == CheckState.Unchecked)//判断复选框是否未被勾选
  136. {
  137. m_comboBox_itemtype.Enabled = false;//锁定下拉框
  138. m_listBox_itemtype.Enabled = false;//锁定列表框
  139. FilterSelectedElems();//根据当前过滤条件筛选元素
  140. }
  141. }
  142. private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)//下拉框选择索引值变化时触发
  143. {
  144. FilterSelectedElems();//根据当前过滤条件筛选元素
  145. }
  146. private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)//下拉框选择索引值变化时触发
  147. {
  148. FilterSelectedElems();//根据当前过滤条件筛选元素
  149. }
  150. private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)//下拉框选择索引值变化时触发
  151. {
  152. FilterSelectedElems();//根据当前过滤条件筛选元素
  153. }
  154. private void button1_Click(object sender, EventArgs e)//点击button按键后触发
  155. {
  156. CopyElementIntoActiveModel();//将列表中的元素复制到当前模型中
  157. this.Close();//关闭当前界面
  158. }
  159. private void comboBox5_SelectedIndexChanged(object sender, EventArgs e)//下拉框选择索引值变化时触发
  160. {
  161. if (string.IsNullOrWhiteSpace(m_comboBox_itemtype.Text))//判断下拉框选择项的文字是否为空
  162. {
  163. return;//返回
  164. }
  165. AddItemTypeIntoListBox();//将ItemType名称添加到列表框中
  166. }
  167. private void listBox1_SelectedIndexChanged(object sender, EventArgs e)//当列表框中选择索引变化时触发
  168. {
  169. FilterSelectedElems();//根据当前过滤条件筛选元素
  170. }
  171. private void SelectSchemaFilePath()//选取Schema文件地址
  172. {
  173. OpenFileDialog dialog = new OpenFileDialog();//打开文件对话框
  174. dialog.Filter = "*.dgn|*.DGN";//设置过滤文件条件
  175. dialog.FilterIndex = 1;//设置过滤索引
  176. if (dialog.ShowDialog() == DialogResult.OK)//判断是否正确输入路径
  177. {
  178. this.m_textbox_filePath.Text = dialog.FileName;//设置文本框中文字为文件路径
  179. }
  180. }
  181. public bool ReadDgnFile()
  182. {
  183. string strDgn = m_textbox_filePath.Text;//文件储存路径
  184. DgnDocument dgnDoc = DgnDocument.CreateForLocalFile(strDgn);//声明DgnDocument对象
  185. DgnFileOwner dgnFileOwner = DgnFile.Create(dgnDoc, DgnFileOpenMode.ReadOnly);//声明一个用于加载部分文件的DgnFile,控制DgnFile的生存期
  186. m_dgnFile = dgnFileOwner.DgnFile;//获得已加载的DgnFile
  187. m_dgnFile.LoadDgnFile(out StatusInt errorStatus);//读取加载DgnFile
  188. ModelIndexCollection modelIndexes = m_dgnFile.GetModelIndexCollection();//获得文件中的所有模型集
  189. if (modelIndexes.Count() > 0)//判断模型数量是否大于零
  190. {
  191. return true;
  192. }
  193. else
  194. {
  195. return false;
  196. }
  197. }
  198. private void DisplayDgnModelNames()
  199. {
  200. m_comboBox_importmodel.Enabled = true;//激活下拉框
  201. m_comboBox_importmodel.Items.Clear();//清空下拉框项目
  202. ModelIndexCollection indexes = m_dgnFile.GetModelIndexCollection();//获得文件中的所有模型索引
  203. foreach (ModelIndex index in indexes)//遍历索引集中的索引
  204. {
  205. DgnModel model = m_dgnFile.LoadRootModelById(out StatusInt status, index.Id);//根据索引获得对应的模型
  206. m_comboBox_importmodel.Items.Add(model.ModelName);//将模型名称添加到下拉框中
  207. }
  208. }
  209. private void GetGraphicElems()
  210. {
  211. ModelId modelId= m_dgnFile.FindModelIdByName(m_comboBox_importmodel.Text);//根据下拉框中的文字在文件中获得对应模型ID
  212. DgnModel dgnModel= m_dgnFile.LoadRootModelById(out StatusInt status,modelId);//根据模型ID获得对应的模型
  213. m_elems = dgnModel.GetGraphicElements().ToList();//获得模型中的图形元素集并将其写入列表
  214. if(m_elems.Count==0)//判断列表中是否存在项
  215. {
  216. MessageCenter.Instance.ShowInfoMessage("No graphic elems found!", "No graphic elems found!",true);//提示未找到图形元素
  217. return;
  218. }
  219. }
  220. private void ShowElemTypeItems()
  221. {
  222. m_comboBox_type.Items.Clear();//清空下拉框中的项
  223. List<string> elemDescs = new List<string>();//声明用于储存元素描述的列表
  224. foreach (Element elem in m_elems)//遍历列表中的元素
  225. {
  226. string elemDesc = elem.Description;//获取元素描述
  227. if (!elemDescs.Contains(elemDesc))//判断列表中是否存在同名字符串
  228. {
  229. elemDescs.Add(elemDesc);//储存字符串到列表中
  230. m_comboBox_type.Items.Add(elemDesc);//在下拉框中添加字符串
  231. }
  232. }
  233. }
  234. private void ShowLevelItems()
  235. {
  236. m_comboBox_level.Items.Clear();//清空下拉框中的项
  237. FileLevelCache cache = m_dgnFile.GetLevelCache();//获得文件中的图层缓存信息
  238. List<string> levelNames = new List<string>();//声明用于储存元素图层的列表
  239. foreach (Element elem in m_elems)//遍历列表中的元素
  240. {
  241. ElementPropertiesGetter getter = new ElementPropertiesGetter(elem);//声明元素属性查看器
  242. LevelId levelId = getter.Level;//获取元素的图层ID
  243. if(levelId==0)//若ID为0则重新执行循环
  244. {
  245. continue;
  246. }
  247. LevelHandle handle = cache.GetLevel(levelId, true);//根据图层ID获取对应的图层句柄
  248. string levelName = handle.Name;//获得图层名称
  249. if (!levelNames.Contains(levelName))//判断列表中是否存在同名字符串
  250. {
  251. levelNames.Add(levelName);//将图层名称添加到列表中
  252. m_comboBox_level.Items.Add(levelName);//在下拉框中添加字符串
  253. }
  254. }
  255. }
  256. private void ShowColorIndexes()
  257. {
  258. m_comboBox_color.Items.Clear();//清空下拉框中的项
  259. List<uint> colorIndeics = new List<uint>();//声明用于储存元素颜色索引的列表
  260. foreach (Element elem in m_elems)//遍历列表中的元素
  261. {
  262. ElementPropertiesGetter getter = new ElementPropertiesGetter(elem);//声明元素属性查看器
  263. uint colorIndex = getter.Color;//获取元素的颜色
  264. if (!colorIndeics.Contains(colorIndex))//判断列表中是否存在相同uint值
  265. {
  266. colorIndeics.Add(colorIndex);//将元素颜色索引添加到列表中
  267. m_comboBox_color.Items.Add(colorIndex);//在下拉框中添加字符串
  268. }
  269. }
  270. }
  271. private void ShowItemTypesInComboBox()
  272. {
  273. m_comboBox_itemtype.Items.Clear();//清空下拉框中的项
  274. IList<ItemTypeLibrary> librarys = ItemTypeLibrary.PopulateListFromFile(m_dgnFile);//获取文件中的所有ItemTypeLibrary列表
  275. List<string> libNames = new List<string>();//声明用于储存ItemTypeLibrary名称的列表
  276. foreach (ItemTypeLibrary library in librarys)//遍历ItemTypeLibrary
  277. {
  278. string libName = library.Name;//获取ItemTypeLibrary的名称
  279. libNames.Add(libName);//将ItemTypeLibrary名称添加到列表中
  280. m_comboBox_itemtype.Items.Add(libName);//在下拉框中添加字符串
  281. }
  282. }
  283. private void FilterSelectedElems()
  284. {
  285. m_selectedElems.Clear();//清空列表
  286. m_elems.ForEach(i => m_selectedElems.Add(i));//复制列表中的值
  287. FileLevelCache cache = m_dgnFile.GetLevelCache();//获得文件中的图层缓存信息
  288. for (int i=0;i< m_selectedElems.Count;i++)//遍历列表中的项
  289. {
  290. if(m_selectedElems[i].IsInvisible)//判断元素是否可见
  291. {
  292. m_selectedElems.Remove(m_selectedElems[i]);//从列表中移除该项
  293. i--;//计数减一
  294. continue;//重新开始循环
  295. }
  296. if (m_comboBox_type.Enabled == true&&!string.IsNullOrWhiteSpace(m_comboBox_type.Text))//判断用于过滤元素类型的下拉框是否激活同时判断下拉框文字是否不为空
  297. {
  298. if(m_selectedElems[i].Description!=m_comboBox_type.Text)//判断元素描述与下拉框文字是否一致
  299. {
  300. m_selectedElems.Remove(m_selectedElems[i]);//从列表中移除该项
  301. i--;//计数减一
  302. continue;//重新开始循环
  303. }
  304. }
  305. if (m_comboBox_level.Enabled == true&&!string.IsNullOrWhiteSpace(m_comboBox_level.Text))//判断用于过滤元素所属图层的下拉框是否激活同时判断下拉框文字是否不为空
  306. {
  307. ElementPropertiesGetter getter = new ElementPropertiesGetter(m_selectedElems[i]);//声明元素属性查看器
  308. LevelId levelId = getter.Level;//获取元素的图层ID
  309. if (levelId == 0)//若ID为0则重新执行循环
  310. {
  311. continue;
  312. }
  313. LevelHandle handle = cache.GetLevel(levelId, true);//根据图层ID获取对应的图层句柄
  314. if (handle.Name!=m_comboBox_level.Text)//判断下拉框中文字是否与元素所属图层名称一致
  315. {
  316. m_selectedElems.Remove(m_selectedElems[i]);//从列表中移除该项
  317. i--;//计数减一
  318. continue;//重新开始循环
  319. }
  320. }
  321. if (m_comboBox_color.Enabled == true&&!string.IsNullOrWhiteSpace(m_comboBox_color.Text))//判断用于过滤元素颜色索引的下拉框是否激活同时判断下拉框文字是否不为空
  322. {
  323. ElementPropertiesGetter getter = new ElementPropertiesGetter(m_selectedElems[i]);//声明元素属性查看器
  324. uint colorIndex = getter.Color;//获取元素颜色索引
  325. if (colorIndex.ToString() != m_comboBox_color.Text)//判断下拉框中文字是否与元素颜色索引一致
  326. {
  327. m_selectedElems.Remove(m_selectedElems[i]);//从列表中移除该项
  328. i--;//计数减一
  329. continue;//重新开始循环
  330. }
  331. }
  332. if(m_comboBox_itemtype.Enabled == true && !string.IsNullOrWhiteSpace(m_comboBox_itemtype.Text)&&m_listBox_itemtype.SelectedItems.Count>0)//判断下拉框是否激活,判断下拉框文字是否不为空同时判断列表框中是否拥有选中的项
  333. {
  334. bool foundItem = false;//声明bool值用于判断元素上是否挂接了ItemType
  335. CustomItemHost host = new CustomItemHost(m_selectedElems[i], true);//声明元素的CustomItemHost
  336. foreach (string type in m_listBox_itemtype.SelectedItems)//遍历列表框中选中项的字符串
  337. {
  338. IDgnECInstance item = host.GetCustomItem(m_comboBox_itemtype.Text, type);//获得CustomItemHost中指定ItemTypeLibrary中的ItemType的EC实例
  339. if (item != null)//判断是否存在指定要求的EC实例
  340. {
  341. foundItem = true;//修改bool值标识已在元素上找到挂接的ItemType
  342. }
  343. }
  344. if(foundItem==false)//判断元素上是否挂接了ItemType
  345. {
  346. m_selectedElems.Remove(m_selectedElems[i]);//从列表中移除该项
  347. i--;//计数减一
  348. continue;//重新开始循环
  349. }
  350. }
  351. }
  352. m_label_elemscount.Text = m_selectedElems.Count().ToString();//在标签中输出经过筛选后的元素个数
  353. }
  354. private void CopyElementIntoActiveModel()
  355. {
  356. #region ProgressBar
  357. m_progressBar_copyprogress.Minimum = 1;//设置进度条的最小值
  358. m_progressBar_copyprogress.Maximum = 100;//设置进度条的最大值
  359. m_progressBar_copyprogress.Value = 1;//设置进度条的值
  360. m_progressBar_copyprogress.Step = 100 / m_selectedElems.Count;//设置进度条的步长
  361. #endregion
  362. for (int i=0;i<m_selectedElems.Count;i++)//遍历元素容器中的元素
  363. {
  364. using (ElementCopyContext copyContext = new ElementCopyContext(m_dgnModel))//复制元素
  365. {
  366. m_progressBar_copyprogress.PerformStep();//进度条按照步长推进
  367. copyContext.DoCopy(m_selectedElems[i]);//复制元素到当前的模型空间中
  368. //DependencyManager.ProcessAffected();
  369. }
  370. }
  371. m_progressBar_copyprogress.Value = 100;//设置进度条的值
  372. if (m_radioButton_outputinfo.Checked == true)//判断指定单选项是否被选择
  373. {
  374. MessageCenter.Instance.ShowInfoMessage(m_selectedElems.Count + " elems import success", m_selectedElems.Count + " elems import success", true);//输出模型导入结果
  375. }
  376. }
  377. private void AddItemTypeIntoListBox()
  378. {
  379. m_listBox_itemtype.Items.Clear();//清空列表框中的项
  380. ItemTypeLibrary itemTypeLibrary = ItemTypeLibrary.FindByName(m_comboBox_itemtype.Text, m_dgnFile);//从文件中中获得指定名称的ItemTypeLibrary
  381. foreach (ItemType itemType in itemTypeLibrary.ItemTypes)//遍历ItemTypeLibrary中的ItemType
  382. {
  383. m_listBox_itemtype.Items.Add(itemType.Name);//将ItemType项的名称添加到列表框中
  384. }
  385. }
  386. }
  387. }
  1. namespace WinformUIIntroduction.UI
  2. {
  3. partial class FilterCopyMenu
  4. {
  5. /// <summary>
  6. /// Required designer variable.
  7. /// </summary>
  8. private System.ComponentModel.IContainer components = null;
  9. /// <summary>
  10. /// Clean up any resources being used.
  11. /// </summary>
  12. /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  13. protected override void Dispose(bool disposing)
  14. {
  15. if (disposing && (components != null))
  16. {
  17. components.Dispose();
  18. }
  19. base.Dispose(disposing);
  20. }
  21. #region Windows Form Designer generated code
  22. /// <summary>
  23. /// Required method for Designer support - do not modify
  24. /// the contents of this method with the code editor.
  25. /// </summary>
  26. private void InitializeComponent()
  27. {
  28. this.m_label_importmodel = new System.Windows.Forms.Label();
  29. this.m_label_filter = new System.Windows.Forms.Label();
  30. this.m_comboBox_type = new System.Windows.Forms.ComboBox();
  31. this.m_label_type = new System.Windows.Forms.Label();
  32. this.m_checkBox_checkall = new System.Windows.Forms.CheckBox();
  33. this.m_checkBox_type = new System.Windows.Forms.CheckBox();
  34. this.m_label_level = new System.Windows.Forms.Label();
  35. this.m_checkBox_level = new System.Windows.Forms.CheckBox();
  36. this.m_comboBox_level = new System.Windows.Forms.ComboBox();
  37. this.m_checkBox_color = new System.Windows.Forms.CheckBox();
  38. this.m_comboBox_color = new System.Windows.Forms.ComboBox();
  39. this.m_label_color = new System.Windows.Forms.Label();
  40. this.m_progressBar_copyprogress = new System.Windows.Forms.ProgressBar();
  41. this.m_radioButton_outputinfo = new System.Windows.Forms.RadioButton();
  42. this.m_label_elems = new System.Windows.Forms.Label();
  43. this.m_label_elemscount = new System.Windows.Forms.Label();
  44. this.m_radioButton_nooutputinfo = new System.Windows.Forms.RadioButton();
  45. this.m_button_execute = new System.Windows.Forms.Button();
  46. this.m_comboBox_importmodel = new System.Windows.Forms.ComboBox();
  47. this.m_label_importpath = new System.Windows.Forms.Label();
  48. this.m_button_importpath = new System.Windows.Forms.Button();
  49. this.m_textbox_filePath = new System.Windows.Forms.TextBox();
  50. this.m_listBox_itemtype = new System.Windows.Forms.ListBox();
  51. this.m_checkBox_itemtype = new System.Windows.Forms.CheckBox();
  52. this.m_label_itemtype = new System.Windows.Forms.Label();
  53. this.m_comboBox_itemtype = new System.Windows.Forms.ComboBox();
  54. this.SuspendLayout();
  55. //
  56. // m_label_importmodel
  57. //
  58. this.m_label_importmodel.AutoSize = true;
  59. this.m_label_importmodel.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  60. this.m_label_importmodel.Location = new System.Drawing.Point(12, 47);
  61. this.m_label_importmodel.Name = "m_label_importmodel";
  62. this.m_label_importmodel.Size = new System.Drawing.Size(80, 17);
  63. this.m_label_importmodel.TabIndex = 1;
  64. this.m_label_importmodel.Text = "导入模型名称";
  65. //
  66. // m_label_filter
  67. //
  68. this.m_label_filter.AutoSize = true;
  69. this.m_label_filter.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  70. this.m_label_filter.Location = new System.Drawing.Point(12, 78);
  71. this.m_label_filter.Name = "m_label_filter";
  72. this.m_label_filter.Size = new System.Drawing.Size(68, 17);
  73. this.m_label_filter.TabIndex = 2;
  74. this.m_label_filter.Text = "元素筛选器";
  75. //
  76. // m_comboBox_type
  77. //
  78. this.m_comboBox_type.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  79. this.m_comboBox_type.Enabled = false;
  80. this.m_comboBox_type.FormattingEnabled = true;
  81. this.m_comboBox_type.Location = new System.Drawing.Point(111, 105);
  82. this.m_comboBox_type.Name = "m_comboBox_type";
  83. this.m_comboBox_type.Size = new System.Drawing.Size(121, 21);
  84. this.m_comboBox_type.TabIndex = 3;
  85. this.m_comboBox_type.SelectedIndexChanged += new System.EventHandler(this.comboBox2_SelectedIndexChanged);
  86. //
  87. // m_label_type
  88. //
  89. this.m_label_type.AutoSize = true;
  90. this.m_label_type.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  91. this.m_label_type.Location = new System.Drawing.Point(12, 106);
  92. this.m_label_type.Name = "m_label_type";
  93. this.m_label_type.Size = new System.Drawing.Size(56, 17);
  94. this.m_label_type.TabIndex = 4;
  95. this.m_label_type.Text = "元素类型";
  96. //
  97. // m_checkBox_checkall
  98. //
  99. this.m_checkBox_checkall.AutoSize = true;
  100. this.m_checkBox_checkall.Enabled = false;
  101. this.m_checkBox_checkall.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  102. this.m_checkBox_checkall.Location = new System.Drawing.Point(238, 77);
  103. this.m_checkBox_checkall.Name = "m_checkBox_checkall";
  104. this.m_checkBox_checkall.Size = new System.Drawing.Size(51, 21);
  105. this.m_checkBox_checkall.TabIndex = 5;
  106. this.m_checkBox_checkall.Text = "全选";
  107. this.m_checkBox_checkall.UseVisualStyleBackColor = true;
  108. this.m_checkBox_checkall.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
  109. //
  110. // m_checkBox_type
  111. //
  112. this.m_checkBox_type.AutoSize = true;
  113. this.m_checkBox_type.Enabled = false;
  114. this.m_checkBox_type.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  115. this.m_checkBox_type.Location = new System.Drawing.Point(238, 108);
  116. this.m_checkBox_type.Name = "m_checkBox_type";
  117. this.m_checkBox_type.Size = new System.Drawing.Size(15, 14);
  118. this.m_checkBox_type.TabIndex = 6;
  119. this.m_checkBox_type.UseVisualStyleBackColor = true;
  120. this.m_checkBox_type.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged);
  121. //
  122. // m_label_level
  123. //
  124. this.m_label_level.AutoSize = true;
  125. this.m_label_level.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  126. this.m_label_level.Location = new System.Drawing.Point(12, 135);
  127. this.m_label_level.Name = "m_label_level";
  128. this.m_label_level.Size = new System.Drawing.Size(80, 17);
  129. this.m_label_level.TabIndex = 7;
  130. this.m_label_level.Text = "元素所属图层";
  131. //
  132. // m_checkBox_level
  133. //
  134. this.m_checkBox_level.AutoSize = true;
  135. this.m_checkBox_level.Enabled = false;
  136. this.m_checkBox_level.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  137. this.m_checkBox_level.Location = new System.Drawing.Point(238, 137);
  138. this.m_checkBox_level.Name = "m_checkBox_level";
  139. this.m_checkBox_level.Size = new System.Drawing.Size(15, 14);
  140. this.m_checkBox_level.TabIndex = 9;
  141. this.m_checkBox_level.UseVisualStyleBackColor = true;
  142. this.m_checkBox_level.CheckedChanged += new System.EventHandler(this.checkBox3_CheckedChanged);
  143. //
  144. // m_comboBox_level
  145. //
  146. this.m_comboBox_level.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  147. this.m_comboBox_level.Enabled = false;
  148. this.m_comboBox_level.FormattingEnabled = true;
  149. this.m_comboBox_level.Location = new System.Drawing.Point(111, 134);
  150. this.m_comboBox_level.Name = "m_comboBox_level";
  151. this.m_comboBox_level.Size = new System.Drawing.Size(121, 21);
  152. this.m_comboBox_level.TabIndex = 8;
  153. this.m_comboBox_level.SelectedIndexChanged += new System.EventHandler(this.comboBox3_SelectedIndexChanged);
  154. //
  155. // m_checkBox_color
  156. //
  157. this.m_checkBox_color.AutoSize = true;
  158. this.m_checkBox_color.Enabled = false;
  159. this.m_checkBox_color.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  160. this.m_checkBox_color.Location = new System.Drawing.Point(238, 166);
  161. this.m_checkBox_color.Name = "m_checkBox_color";
  162. this.m_checkBox_color.Size = new System.Drawing.Size(15, 14);
  163. this.m_checkBox_color.TabIndex = 12;
  164. this.m_checkBox_color.UseVisualStyleBackColor = true;
  165. this.m_checkBox_color.CheckedChanged += new System.EventHandler(this.checkBox4_CheckedChanged);
  166. //
  167. // m_comboBox_color
  168. //
  169. this.m_comboBox_color.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  170. this.m_comboBox_color.Enabled = false;
  171. this.m_comboBox_color.FormattingEnabled = true;
  172. this.m_comboBox_color.Location = new System.Drawing.Point(111, 163);
  173. this.m_comboBox_color.Name = "m_comboBox_color";
  174. this.m_comboBox_color.Size = new System.Drawing.Size(121, 21);
  175. this.m_comboBox_color.TabIndex = 11;
  176. this.m_comboBox_color.SelectedIndexChanged += new System.EventHandler(this.comboBox4_SelectedIndexChanged);
  177. //
  178. // m_label_color
  179. //
  180. this.m_label_color.AutoSize = true;
  181. this.m_label_color.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  182. this.m_label_color.Location = new System.Drawing.Point(12, 164);
  183. this.m_label_color.Name = "m_label_color";
  184. this.m_label_color.Size = new System.Drawing.Size(92, 17);
  185. this.m_label_color.TabIndex = 10;
  186. this.m_label_color.Text = "元素颜色索引值";
  187. //
  188. // m_progressBar_copyprogress
  189. //
  190. this.m_progressBar_copyprogress.Location = new System.Drawing.Point(-1, 455);
  191. this.m_progressBar_copyprogress.Name = "m_progressBar_copyprogress";
  192. this.m_progressBar_copyprogress.Size = new System.Drawing.Size(301, 23);
  193. this.m_progressBar_copyprogress.TabIndex = 13;
  194. //
  195. // m_radioButton_outputinfo
  196. //
  197. this.m_radioButton_outputinfo.AutoSize = true;
  198. this.m_radioButton_outputinfo.Enabled = false;
  199. this.m_radioButton_outputinfo.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  200. this.m_radioButton_outputinfo.Location = new System.Drawing.Point(12, 377);
  201. this.m_radioButton_outputinfo.Name = "m_radioButton_outputinfo";
  202. this.m_radioButton_outputinfo.Size = new System.Drawing.Size(98, 21);
  203. this.m_radioButton_outputinfo.TabIndex = 14;
  204. this.m_radioButton_outputinfo.TabStop = true;
  205. this.m_radioButton_outputinfo.Text = "输出生成信息";
  206. this.m_radioButton_outputinfo.UseVisualStyleBackColor = true;
  207. //
  208. // m_label_elems
  209. //
  210. this.m_label_elems.AutoSize = true;
  211. this.m_label_elems.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  212. this.m_label_elems.Location = new System.Drawing.Point(203, 377);
  213. this.m_label_elems.Name = "m_label_elems";
  214. this.m_label_elems.Size = new System.Drawing.Size(68, 17);
  215. this.m_label_elems.TabIndex = 15;
  216. this.m_label_elems.Text = "元素合计:";
  217. //
  218. // m_label_elemscount
  219. //
  220. this.m_label_elemscount.AutoSize = true;
  221. this.m_label_elemscount.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  222. this.m_label_elemscount.Location = new System.Drawing.Point(270, 377);
  223. this.m_label_elemscount.Name = "m_label_elemscount";
  224. this.m_label_elemscount.Size = new System.Drawing.Size(15, 17);
  225. this.m_label_elemscount.TabIndex = 16;
  226. this.m_label_elemscount.Text = "0";
  227. //
  228. // m_radioButton_nooutputinfo
  229. //
  230. this.m_radioButton_nooutputinfo.AutoSize = true;
  231. this.m_radioButton_nooutputinfo.Enabled = false;
  232. this.m_radioButton_nooutputinfo.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  233. this.m_radioButton_nooutputinfo.Location = new System.Drawing.Point(12, 400);
  234. this.m_radioButton_nooutputinfo.Name = "m_radioButton_nooutputinfo";
  235. this.m_radioButton_nooutputinfo.Size = new System.Drawing.Size(110, 21);
  236. this.m_radioButton_nooutputinfo.TabIndex = 17;
  237. this.m_radioButton_nooutputinfo.TabStop = true;
  238. this.m_radioButton_nooutputinfo.Text = "不输出生成信息";
  239. this.m_radioButton_nooutputinfo.UseVisualStyleBackColor = true;
  240. //
  241. // m_button_execute
  242. //
  243. this.m_button_execute.Enabled = false;
  244. this.m_button_execute.Location = new System.Drawing.Point(111, 426);
  245. this.m_button_execute.Name = "m_button_execute";
  246. this.m_button_execute.Size = new System.Drawing.Size(75, 23);
  247. this.m_button_execute.TabIndex = 20;
  248. this.m_button_execute.Text = "执行";
  249. this.m_button_execute.UseVisualStyleBackColor = true;
  250. this.m_button_execute.Click += new System.EventHandler(this.button1_Click);
  251. //
  252. // m_comboBox_importmodel
  253. //
  254. this.m_comboBox_importmodel.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  255. this.m_comboBox_importmodel.Enabled = false;
  256. this.m_comboBox_importmodel.FormattingEnabled = true;
  257. this.m_comboBox_importmodel.Location = new System.Drawing.Point(111, 46);
  258. this.m_comboBox_importmodel.Name = "m_comboBox_importmodel";
  259. this.m_comboBox_importmodel.Size = new System.Drawing.Size(121, 21);
  260. this.m_comboBox_importmodel.TabIndex = 21;
  261. this.m_comboBox_importmodel.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
  262. //
  263. // m_label_importpath
  264. //
  265. this.m_label_importpath.AutoSize = true;
  266. this.m_label_importpath.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  267. this.m_label_importpath.Location = new System.Drawing.Point(12, 9);
  268. this.m_label_importpath.Name = "m_label_importpath";
  269. this.m_label_importpath.Size = new System.Drawing.Size(80, 17);
  270. this.m_label_importpath.TabIndex = 22;
  271. this.m_label_importpath.Text = "导入文件地址";
  272. //
  273. // m_button_importpath
  274. //
  275. this.m_button_importpath.Location = new System.Drawing.Point(258, 8);
  276. this.m_button_importpath.Name = "m_button_importpath";
  277. this.m_button_importpath.Size = new System.Drawing.Size(30, 20);
  278. this.m_button_importpath.TabIndex = 24;
  279. this.m_button_importpath.Text = "...";
  280. this.m_button_importpath.UseVisualStyleBackColor = true;
  281. this.m_button_importpath.Click += new System.EventHandler(this.button2_Click);
  282. //
  283. // m_textbox_filePath
  284. //
  285. this.m_textbox_filePath.Location = new System.Drawing.Point(111, 8);
  286. this.m_textbox_filePath.Name = "m_textbox_filePath";
  287. this.m_textbox_filePath.ReadOnly = true;
  288. this.m_textbox_filePath.Size = new System.Drawing.Size(149, 20);
  289. this.m_textbox_filePath.TabIndex = 25;
  290. this.m_textbox_filePath.TextChanged += new System.EventHandler(this.m_textbox_modelname_TextChanged);
  291. //
  292. // m_listBox_itemtype
  293. //
  294. this.m_listBox_itemtype.Enabled = false;
  295. this.m_listBox_itemtype.FormattingEnabled = true;
  296. this.m_listBox_itemtype.Location = new System.Drawing.Point(111, 214);
  297. this.m_listBox_itemtype.Name = "m_listBox_itemtype";
  298. this.m_listBox_itemtype.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended;
  299. this.m_listBox_itemtype.Size = new System.Drawing.Size(121, 160);
  300. this.m_listBox_itemtype.TabIndex = 26;
  301. this.m_listBox_itemtype.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
  302. //
  303. // m_checkBox_itemtype
  304. //
  305. this.m_checkBox_itemtype.AutoSize = true;
  306. this.m_checkBox_itemtype.Enabled = false;
  307. this.m_checkBox_itemtype.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  308. this.m_checkBox_itemtype.Location = new System.Drawing.Point(238, 192);
  309. this.m_checkBox_itemtype.Name = "m_checkBox_itemtype";
  310. this.m_checkBox_itemtype.Size = new System.Drawing.Size(15, 14);
  311. this.m_checkBox_itemtype.TabIndex = 27;
  312. this.m_checkBox_itemtype.UseVisualStyleBackColor = true;
  313. this.m_checkBox_itemtype.CheckedChanged += new System.EventHandler(this.checkBox5_CheckedChanged);
  314. //
  315. // m_label_itemtype
  316. //
  317. this.m_label_itemtype.AutoSize = true;
  318. this.m_label_itemtype.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  319. this.m_label_itemtype.Location = new System.Drawing.Point(12, 190);
  320. this.m_label_itemtype.Name = "m_label_itemtype";
  321. this.m_label_itemtype.Size = new System.Drawing.Size(62, 17);
  322. this.m_label_itemtype.TabIndex = 28;
  323. this.m_label_itemtype.Text = "ItemType";
  324. //
  325. // m_comboBox_itemtype
  326. //
  327. this.m_comboBox_itemtype.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  328. this.m_comboBox_itemtype.Enabled = false;
  329. this.m_comboBox_itemtype.FormattingEnabled = true;
  330. this.m_comboBox_itemtype.Location = new System.Drawing.Point(111, 189);
  331. this.m_comboBox_itemtype.Name = "m_comboBox_itemtype";
  332. this.m_comboBox_itemtype.Size = new System.Drawing.Size(121, 21);
  333. this.m_comboBox_itemtype.TabIndex = 29;
  334. this.m_comboBox_itemtype.SelectedIndexChanged += new System.EventHandler(this.comboBox5_SelectedIndexChanged);
  335. //
  336. // FilterCopyMenu
  337. //
  338. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
  339. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  340. this.ClientSize = new System.Drawing.Size(299, 478);
  341. this.Controls.Add(this.m_comboBox_itemtype);
  342. this.Controls.Add(this.m_label_itemtype);
  343. this.Controls.Add(this.m_checkBox_itemtype);
  344. this.Controls.Add(this.m_listBox_itemtype);
  345. this.Controls.Add(this.m_textbox_filePath);
  346. this.Controls.Add(this.m_button_importpath);
  347. this.Controls.Add(this.m_label_importpath);
  348. this.Controls.Add(this.m_comboBox_importmodel);
  349. this.Controls.Add(this.m_button_execute);
  350. this.Controls.Add(this.m_radioButton_nooutputinfo);
  351. this.Controls.Add(this.m_label_elemscount);
  352. this.Controls.Add(this.m_label_elems);
  353. this.Controls.Add(this.m_radioButton_outputinfo);
  354. this.Controls.Add(this.m_progressBar_copyprogress);
  355. this.Controls.Add(this.m_checkBox_color);
  356. this.Controls.Add(this.m_comboBox_color);
  357. this.Controls.Add(this.m_label_color);
  358. this.Controls.Add(this.m_checkBox_level);
  359. this.Controls.Add(this.m_comboBox_level);
  360. this.Controls.Add(this.m_label_level);
  361. this.Controls.Add(this.m_checkBox_type);
  362. this.Controls.Add(this.m_checkBox_checkall);
  363. this.Controls.Add(this.m_label_type);
  364. this.Controls.Add(this.m_comboBox_type);
  365. this.Controls.Add(this.m_label_filter);
  366. this.Controls.Add(this.m_label_importmodel);
  367. this.MaximizeBox = false;
  368. this.Name = "FilterCopyMenu";
  369. this.ShowIcon = false;
  370. this.Text = "FilterCopyMenu";
  371. this.TopMost = true;
  372. this.ResumeLayout(false);
  373. this.PerformLayout();
  374. }
  375. #endregion
  376. private System.Windows.Forms.Label m_label_importmodel;
  377. private System.Windows.Forms.Label m_label_filter;
  378. private System.Windows.Forms.ComboBox m_comboBox_type;
  379. private System.Windows.Forms.Label m_label_type;
  380. private System.Windows.Forms.CheckBox m_checkBox_checkall;
  381. private System.Windows.Forms.CheckBox m_checkBox_type;
  382. private System.Windows.Forms.Label m_label_level;
  383. private System.Windows.Forms.CheckBox m_checkBox_level;
  384. private System.Windows.Forms.ComboBox m_comboBox_level;
  385. private System.Windows.Forms.CheckBox m_checkBox_color;
  386. private System.Windows.Forms.ComboBox m_comboBox_color;
  387. private System.Windows.Forms.Label m_label_color;
  388. private System.Windows.Forms.ProgressBar m_progressBar_copyprogress;
  389. private System.Windows.Forms.RadioButton m_radioButton_outputinfo;
  390. private System.Windows.Forms.Label m_label_elems;
  391. private System.Windows.Forms.Label m_label_elemscount;
  392. private System.Windows.Forms.RadioButton m_radioButton_nooutputinfo;
  393. private System.Windows.Forms.Button m_button_execute;
  394. private System.Windows.Forms.ComboBox m_comboBox_importmodel;
  395. private System.Windows.Forms.Label m_label_importpath;
  396. private System.Windows.Forms.Button m_button_importpath;
  397. private System.Windows.Forms.TextBox m_textbox_filePath;
  398. private System.Windows.Forms.ListBox m_listBox_itemtype;
  399. private System.Windows.Forms.CheckBox m_checkBox_itemtype;
  400. private System.Windows.Forms.Label m_label_itemtype;
  401. private System.Windows.Forms.ComboBox m_comboBox_itemtype;
  402. }
  403. }

3.gif
图58 文件选择复制工具

注意事项

  • 在MicroStation二次开发的环境下使用WinForm时,需要将继承的Form修改为Bentley.MstnPlatformNET.WinForms.Adapter
  • 在MicroStation中需要调用界面时,需要首先对界面进行声明,然后使用模态显示(ShowDialog)和非模态显示(Show),模态与非模态窗体的主要区别是窗体显示的时候是否可以操作其他窗体。模态窗体不允许操作其他窗体,非模态窗体可以操作其他窗体。
    1. BeamCreateMenu menu = new BeamCreateMenu();//声明界面
    2. menu.Show();//展示界面