2011-05-26 14 views

回答

0

我相信,你必须实现EvenSink以访问“ShapesDeleted”,即

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

上面的代码会帮助你,如果你正在寻找“BeforeShapeDelete”不“之后” ShapeDelete事件;)

3

Visio Primary Interop Assembly将这些事件公开为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版本包含了许多有用的示例,其中包括一个名为“形状添加\删除事件”的示例。如果您拥有2010版本,可以转到“开始”菜单\程序\ Microsoft Office 2010开发人员资源\ Microsoft Visio 2010 SDK \ Microsoft Visio代码示例库来浏览示例。

相关问题