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

发布于 2024-11-10 01:53:56 字数 61 浏览 1 评论 0原文

我认为标题或问题已经足够清楚了。我看到了一些关于EventSink的东西,但我发现它很难使用。有什么提示吗?

I think the title or the question is clear enough. I saw something about the EventSink, but I found it difficult to use. Any hint?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁月如刀 2024-11-17 01:53:56

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 代码示例库来浏览示例。

The Visio Primary Interop Assembly exposes these events as C# events therefore you can simply hook the event with a delegate.

See this simple example:

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));
        }
    }
}

If you haven't already downloaded the Visio SDK you should do so. Recent versions of the SDK it contains many useful examples include one called "Shape Add\Delete Event". If you have the 2010 version can browse the examples by going to Start Menu\Programs\Microsoft Office 2010 Developer Resources\Microsoft Visio 2010 SDK\Microsoft Visio Code Samples Library.

水中月 2024-11-17 01:53:56

我相信您必须实现 EvenSink 才能访问“ShapesDeleted”,即

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

如果您正在寻找事件“BeforeShapeDelete”而不是“after”ShapeDelete,上面的代码将为您提供帮助;)

I believe that you have to implement EvenSink to get access to "ShapesDeleted", i.e.

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

the code above will help you if you are looking for the event "BeforeShapeDelete" not the "after"ShapeDelete ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文