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

推荐订阅源

月光博客
月光博客
有赞技术团队
有赞技术团队
S
SegmentFault 最新的问题
宝玉的分享
宝玉的分享
量子位
小众软件
小众软件
The Cloudflare Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
大猫的无限游戏
大猫的无限游戏
C
Check Point Blog
G
Google Developers Blog
博客园 - 叶小钗
H
Help Net Security
Jina AI
Jina AI
Y
Y Combinator Blog
Last Week in AI
Last Week in AI
GbyAI
GbyAI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Apple Machine Learning Research
Apple Machine Learning Research
MyScale Blog
MyScale Blog
T
Tailwind CSS Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Vercel News
Vercel News

博客园 - 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的处理