Есть ли какое-либо событие OnShapeMoved или OnShapeDeleted в Visio? - PullRequest
1 голос
/ 26 мая 2011

Я думаю, что название или вопрос достаточно ясны. Я видел кое-что о EventSink, но мне было трудно его использовать. Любой намек?

Ответы [ 2 ]

3 голосов
/ 27 мая 2011

Первичная сборка взаимодействия 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.

0 голосов
/ 15 марта 2012

Я считаю, что вы должны реализовать EvenSink, чтобы получить доступ к "ShapesDeleted", т.е.

 (short)Microsoft.Office.Interop.Visio.VisEventCodes.visEvtCodeShapeDelete

код выше поможет вам, если вы ищете событие «BeforeShapeDelete», а не «after» ShapeDelete;)

...