Discerning, in many cases, is very much needed, for example, if we improve a set of systems, to the Sichuan disaster relief funds to raise, procurement, distribution and other steps can be very discerning, I believe the world will be much quieter.
Similarly, for a program that uses Visio for two development, you need to know that the user has added those devices, removed those devices, and modified those devices, so that you can effectively control the entire system's data, otherwise "disaster relief" money may be lost, hehe.
So what can we do to effectively deal with these events and make the changes to the equipment more discerning?
I introduced an article "C # for Visio development event handling," which also describes the various event listening, we want to track the device, basically only need to listen to these events and deal with it.
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");
object IVisEventProc.VisEventProc(short eventCode, object source, int eventId,
int eventSequenceNumber, object subject, object moreInfo)
{
......
switch (eventCode)
{
case (short)VisEventCodes.visEvtShape + unchecked((short)VisEventCodes.visEvtAdd):
eventShape = (Shape)subject;
handleShapeAdd(eventShape);
break;
case (short)VisEventCodes.visEvtDel + (short)VisEventCodes.visEvtShape:
eventShape = (Shape)subject;
handleShapeDelete(eventShape);
break;
case (short)VisEventCodes.visEvtCell + (short)VisEventCodes.visEvtMod:
Visio.Cell cell = (Cell)subject;
if (cell.Name.IndexOf("Prop") >= 0)//限制只执行自定义事件一次
{
eventShape = cell.Shape;
handleCellModify(eventShape);
}
break;
default:
break;
}
return result;
}