C#-Visio中是否有任何OnShapeMoved或OnShapeDeleted事件?

| 我认为标题或问题很清楚。我看到了一些有关EventSink的信息,但发现它很难使用。有什么提示吗?     
已邀请:
我相信您必须实施EvenSink才能访问\“ ShapesDeleted \”,即
 (short)Microsoft.Office.Interop.Visio.VisEventCodes.visEvtCodeShapeDelete
如果您正在查找事件\“ BeforeShapeDelete \”而不是\“ after \” ShapeDelete;),以上代码将为您提供帮助。     
Visio主互操作程序集将这些事件公开为C#事件,因此您可以简单地将事件与委托挂钩。 看这个简单的例子:
namespace VisioEventsExample
{
    using System;
    using Microsoft.Office.Interop.Visio;

    class Program
    {
        public static void Main(string[] args)
        {
            Application app = new Application();
            Document doc = app.Documents.Add(\"\");
            Page page = doc.Pages[1];

            // Setup event handles for the events you are intrested in.

            // Shape deleted is easy.
            page.BeforeShapeDelete += 
                new EPage_BeforeShapeDeleteEventHandler(onBeforeShapeDelete);

            // To find out if a shape has moved hook the cell changed event 
            // and then check to see if PinX or PinY changed.
            page.CellChanged += 
                new EPage_CellChangedEventHandler(onCellChanged);

            // In C# 4 for you can simply do this:
            //            
            //   page.BeforeShapeDelete += onBeforeShapeDelete;
            //   page.CellChanged += onCellChanged;

            // Now wait for the events.
            Console.WriteLine(\"Wait for events. Press any key to stop.\");
            Console.ReadKey();
        }

        // This will be called when a shape sheet cell for a
        // shape on the page is changed. To know if the shape
        // was moved see of the pin was changed. This will 
        // fire twice if the shape is moved horizontally and 
        // vertically.
        private static void onCellChanged(Cell cell)
        {
            if (cell.Name == \"PinX\" || cell.Name == \"PinY\")
            {
                Console.WriteLine(
                    string.Format(\"Shape {0} moved\", cell.Shape.Name));
            }            
        }

        // This will be called when a shape is deleted from the page.
        private static void onBeforeShapeDelete(Shape shape)
        {
            Console.WriteLine(string.Format(\"Shape deleted {0}\", shape.Name));
        }
    }
}
如果尚未下载Visio SDK,则应这样做。 SDK的最新版本包含许多有用的示例,其中包括一个称为“ Shape Add \\ Delete Event \”的示例。如果您拥有2010版本,则可以通过转到“开始”菜单\\程序\\ Microsoft Office 2010开发人员资源\\ Microsoft Visio 2010 SDK \\ Microsoft Visio代码示例库来浏览示例。     

要回复问题请先登录注册