C#进行Visio开发的事件处理
Visio的二次开发过程中,必定要处理很多Visio事件,事件基本上分为三类:Document事件、Applicaiton事件、AxDrawingControl事件。Document事件是每个文档创建或者打开都需要重新绑定一次的,但是Application事件不变,即不需要重新绑定,AxDrawingControl是ActiveX控件的事件响应。
在C#进行Visio的开发中,通过继承接口IVisEventProc,可以创建事件的侦听处理类,如下所示:
事件有很多类,有Application级别的,有Document级别的,有Page级别的,有Shape级别的,有Windows级别的,有Cell级别的..............,下面截取一部分事件代码看看
将事件和我们的处理函数联系起来,还需要对事件进行侦听,即AddAdvise,下面列出一段如何侦听事件的代码供参考
具体的使用,最好下载Visio2007 SDK进行学习,自己编写一些例子对事件进行处理
在C#进行Visio的开发中,通过继承接口IVisEventProc,可以创建事件的侦听处理类,如下所示:
[ComVisible(true)]
public sealed class EventSink2 : IVisEventProc
{
..
object IVisEventProc.VisEventProc(short eventCode, object source, int eventId,
int eventSequenceNumber, object subject, object moreInfo)
{
}
}
public sealed class EventSink2 : IVisEventProc
{
..
object IVisEventProc.VisEventProc(short eventCode, object source, int eventId,
int eventSequenceNumber, object subject, object moreInfo)
{
}
}
事件有很多类,有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:
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:
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:
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:
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:
还有很多很多..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;
EventList applicationEvents = eventApplication.EventList;
EventList documentEvents = eventDocument.EventList;
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");
Event newEvent = null;
EventList applicationEvents = eventApplication.EventList;
EventList documentEvents = eventDocument.EventList;
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进行学习,自己编写一些例子对事件进行处理
专注于代码生成工具、.Net/.NetCore 框架架构及软件开发,以及各种Vue.js的前端技术应用。著有Winform开发框架/混合式开发框架、微信开发框架、Bootstrap开发框架、ABP开发框架、SqlSugar开发框架等框架产品。
转载请注明出处:撰写人:伍华聪 http://www.iqidi.com
转载请注明出处:撰写人:伍华聪 http://www.iqidi.com