惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
Stack Overflow Blog
Stack Overflow Blog
人人都是产品经理
人人都是产品经理
Y
Y Combinator Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
D
DataBreaches.Net
GbyAI
GbyAI
Microsoft Security Blog
Microsoft Security Blog
博客园_首页
大猫的无限游戏
大猫的无限游戏
Jina AI
Jina AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Engineering at Meta
Engineering at Meta
IT之家
IT之家
MongoDB | Blog
MongoDB | Blog
The GitHub Blog
The GitHub Blog
月光博客
月光博客
U
Unit 42
Hugging Face - Blog
Hugging Face - Blog
博客园 - 叶小钗
腾讯CDC
B
Blog RSS Feed
博客园 - Franky
爱范儿
爱范儿

博客园 - ant-boss

pl/sql转义字符的问题 备份/恢复SQL Server EXP/IMP 命令参数 Programming with the Microsoft Office Visio 2003 ActiveX Control 使用Visio 2003 Drawing Control开发应用(5) 使用Visio 2003 Drawing Control开发应用(4) 使用Visio 2003 Drawing Control开发应用(3) 使用Visio 2003 Drawing Control开发应用(1) Visio 2003 开发入门 软件数字签名 在ASP.NET下用Microsoft Excel进行数据分析与报表 水晶报表常见问题(转载) Access 类型转换函数 My97日期控件 My97 DatePicker Ver 3.0.1 showModalDialog 使用TransactionScope 实现事务管理 datagrid数据导出到excel文件给客户端下载的几种方法 VSS(Visual SourceSafe)使用入门 [转] 使用asp.net 2.0和SQL SERVER 2005构建多层应用
使用Visio 2003 Drawing Control开发应用(2)
ant-boss · 2007-10-25 · via 博客园 - ant-boss

这个控件直接暴露出来的事件并不是很多,但是也可以完成大部分的功能了。我没有用过的就不敢乱说了,下面说几个我用到的事件。

BeforeSelectionDelete:在Visio中,Selection是一个选中shape的集合。这个事件在删除前发生。这里因为我对于每个图形上的Shape都有关联的一些属性。所以为了实现Undo的时候恢复原来的内容,必须要在删除前做保留。比如:
if(this.visClickedShape != null)
{
 for(int i = 0; i < busResource.Components.Count; i++)
 {
  BusinessProcessComponent temp = busResource.Components[i] as BusinessProcessComponent;
  if(temp.ComponentName.Trim() == this.visClickedShape.Data1.Trim() &&
   temp.RunNumber == Convert.ToInt32(this.visClickedShape.Data2))
  {
   componentDeleted = temp.Clone() as BusinessProcessComponent;
   componentDeleted.Parameters.Clear();
   for(int j = 0; j < temp.Parameters.Count; j++)
    componentDeleted.Parameters.Add((temp.Parameters[j] as BusinessProcessComponentParameter).Clone());
   componentDeleted.Results.Clear();
   for(int j = 0; j < temp.Results.Count; j++)
    componentDeleted.Results.Add((temp.Results[j] as BusinessProcessComponentResult).Clone());
  }
 }
 System.Diagnostics.Debug.WriteLine("Set Delete flag");
 this.isDeleted = true;
}
这里我处理的是我定义的一个visClickedShape,而不是e.selection,因为是暂时处理了其中一个shape的内容备份,如果是对所有选中内容备份,就应该在e.selection中取出所有的shape进行备份。另外,这里用到了Data1和Data2,这里我放了一些数据,关

于Data1和Data2,我将在后面在讲操纵visio shapesheet和xml的时候说明。

KeyUpEvent,KeyPressEvent,KeyDownEvent:这些事件是处理键盘事件的。但是我发现有些时候,这些事件并不一定能正确响应。

MouseUpEvent等:处理鼠标事件,我用他来处理自定义菜单。
this.visClickedShape = VisioUtility.GetClickedShape(visPage, e.x, e.y); // 根据鼠标点确定选择的Shape
// 如果为鼠标右键点击
if(e.button == (int)Visio.VisKeyButtonFlags.visMouseRight)
{
 e.cancelDefault = true; // 取消Visio的鼠标右键事件响应
 if(this.visClickedShape != null)
 {
  this.contextComponent.Show(this, PageUnitsToPixels(ref visDrawing, e.x, e.y)); // 显示组件属性右键菜单
 }
 else
  this.contextBusinessProcess.Show(this, PageUnitsToPixels(ref visDrawing, e.x, e.y)); // 显示流程属性右键菜单
这里的PageUnitsToPixels是计算鼠标右键点对应Visio图形区内的鼠标点位置

ShapeAdded:这个事件在图形区有新的shape添加进去时激发。
事件的参数e中的shape就是添加的shape,可以对这个shape进行一些设置。比如:
if(e.shape.Master == null)
 return;
if(e.shape.Master.NameU == "Dynamic connector")
{
 // 如果是动态连接线,设置终点的箭头属性
 e.shape.get_CellsSRC((short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowLine, (short)Visio.VisCellIndices.visLineEndArrow).FormulaU = "8";
 e.shape.get_CellsSRC((short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowLine, (short)Visio.VisCellIndices.visLineArrowSize).FormulaU = "4";
 return;
}

Visio.Shape shapeAdded = e.shape;

还有其他事件,可以根据需要来使用

除了这些事件外,对各种对象还有单独事件可以利用。
比如:
this.axDrawingControl1.Window.Application.ActivePage.ConnectionsAdded += new Microsoft.Office.Interop.Visio.EPage_ConnectionsAddedEventHandler(ActivePage_ConnectionsAdded);
但是,我记得这样试过没有成功,也许是我自己的问题,后来因为不怎么需要,就没有研究了。

下一节介绍 对象的ShapeSheet和visio xml的处理