C#进行Visio开发的事件处理
Visio的二次开发过程中,必定要处理很多Visio事件,事件基本上分为三类:Document事件、Applicaiton事件、AxDrawingControl事件。Document事件是每个文档创建或者打开都需要重新绑定一次的,但是Application事件不变,即不需要重新绑定,AxDrawingControl是ActiveX控件的事件响应。
在C#进行Visio的开发中,通过继承接口IVisEventProc,可以创建事件的侦听处理类,如下所示:
[ComVisible(true)]
public sealed class EventSink2 : IVisEventProc
{
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/dot.gif)
![](/Images/dot.gif)
..
![](/Images/OutliningIndicators/InBlock.gif)
object IVisEventProc.VisEventProc(short eventCode, object source, int eventId,
int eventSequenceNumber, object subject, object moreInfo)
{
![](/Images/dot.gif)
}
}
事件有很多类,有Application级别的,有Document级别的,有Page级别的,有Shape级别的,有Windows级别的,有Cell级别的..............,下面截取一部分事件代码看看
// Document event codes
case (short)Microsoft.Office.Interop.Visio.VisEventCodes.
visEvtDoc + (short)Microsoft.Office.Interop.Visio.
VisEventCodes.visEvtDel:
case (short)Microsoft.Office.Interop.Visio.VisEventCodes.
visEvtCodeBefDocSave:
case (short)Microsoft.Office.Interop.Visio.VisEventCodes.
visEvtCodeBefDocSaveAs:
case (short)Microsoft.Office.Interop.Visio.VisEventCodes.
visEvtCodeDocDesign:
// Page event codes
case (short)Microsoft.Office.Interop.Visio.VisEventCodes.
visEvtPage + (short)Microsoft.Office.Interop.Visio.
VisEventCodes.visEvtDel:
case (short)Microsoft.Office.Interop.Visio.VisEventCodes.
visEvtPage + visEvtAdd:
case (short)Microsoft.Office.Interop.Visio.VisEventCodes.
visEvtPage + (short)Microsoft.Office.Interop.Visio.
VisEventCodes.visEvtMod:
// Master event codes
case (short)Microsoft.Office.Interop.Visio.VisEventCodes.
visEvtMaster + (short)Microsoft.Office.Interop.Visio.
VisEventCodes.visEvtDel:
case (short)Microsoft.Office.Interop.Visio.VisEventCodes.
visEvtMaster + (short)Microsoft.Office.Interop.Visio.
VisEventCodes.visEvtMod:
case (short)Microsoft.Office.Interop.Visio.VisEventCodes.
visEvtCodeCancelMasterDel:
// Shape event codes
case (short)Microsoft.Office.Interop.Visio.VisEventCodes.
visEvtShape + (short)Microsoft.Office.Interop.Visio.
VisEventCodes.visEvtDel:
case (short)Microsoft.Office.Interop.Visio.VisEventCodes.
visEvtCodeShapeBeforeTextEdit:
case (short)Microsoft.Office.Interop.Visio.VisEventCodes.
visEvtShape + visEvtAdd:
case (short)Microsoft.Office.Interop.Visio.VisEventCodes.
visEvtShape + (short)Microsoft.Office.Interop.Visio.
VisEventCodes.visEvtMod:
// Cell event codes
case (short)Microsoft.Office.Interop.Visio.VisEventCodes.
visEvtCell + (short)Microsoft.Office.Interop.Visio.
VisEventCodes.visEvtMod:
case (short)Microsoft.Office.Interop.Visio.VisEventCodes.
visEvtFormula + (short)Microsoft.Office.Interop.Visio.
VisEventCodes.visEvtMod:还有很多很多..
将事件和我们的处理函数联系起来,还需要对事件进行侦听,即AddAdvise,下面列出一段如何侦听事件的代码供参考
const string sink = "";
Event newEvent = null;
![](/Images/OutliningIndicators/None.gif)
EventList applicationEvents = eventApplication.EventList;
EventList documentEvents = eventDocument.EventList;
![](/Images/OutliningIndicators/None.gif)
newEvent = documentEvents.AddAdvise(
(unchecked((short)VisEventCodes.visEvtAdd) + (short)VisEventCodes.visEvtShape),
(IVisEventProc)this, sink, "ShapeAdd");
newEvent = documentEvents.AddAdvise(
(short)VisEventCodes.visEvtDel + (short)VisEventCodes.visEvtShape,
(IVisEventProc)this, sink, "ShapeDelete");
newEvent = documentEvents.AddAdvise(
(short)VisEventCodes.visEvtMod + (short)VisEventCodes.visEvtCell,
(IVisEventProc)this, sink, "CellChanged");
newEvent = documentEvents.AddAdvise(
(short)VisEventCodes.visEvtCodeShapeExitTextEdit,
(IVisEventProc)this, sink, "ShapeExitedTextEdit");
newEvent = documentEvents.AddAdvise(
(short)VisEventCodes.visEvtCodeQueryCancelSelDel,
(IVisEventProc)this, sink, "QueryCancelSelectionDelete");
具体的使用,最好下载Visio2007 SDK进行学习,自己编写一些例子对事件进行处理
在C#进行Visio的开发中,通过继承接口IVisEventProc,可以创建事件的侦听处理类,如下所示:
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/dot.gif)
![](/Images/dot.gif)
![](/Images/dot.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/dot.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
事件有很多类,有Application级别的,有Document级别的,有Page级别的,有Shape级别的,有Windows级别的,有Cell级别的..............,下面截取一部分事件代码看看
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
将事件和我们的处理函数联系起来,还需要对事件进行侦听,即AddAdvise,下面列出一段如何侦听事件的代码供参考
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
具体的使用,最好下载Visio2007 SDK进行学习,自己编写一些例子对事件进行处理
![](http://www.cnblogs.com/Images/OutliningIndicators/None.gif)
转载请注明出处:撰写人:伍华聪 http://www.iqidi.com