Events C#-Visio中是否存在任何OnShapeMoved或OnShapeDeleted事件?
我认为题目或问题已经很清楚了。我看到了EventSink的一些东西,但我发现它很难使用。有什么提示吗?将这些事件公开为C#事件,因此您可以简单地用委托钩住事件 请参见以下简单示例:Events C#-Visio中是否存在任何OnShapeMoved或OnShapeDeleted事件?,events,visio,Events,Visio,我认为题目或问题已经很清楚了。我看到了EventSink的一些东西,但我发现它很难使用。有什么提示吗?将这些事件公开为C#事件,因此您可以简单地用委托钩住事件 请参见以下简单示例: namespace VisioEventsExample { using System; using Microsoft.Office.Interop.Visio; class Program { public static void Main(string[] ar
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));
}
}
}
如果您尚未下载,则应该下载。SDK的最新版本包含许多有用的示例,其中包括一个名为“Shape Add\Delete Event”的示例。如果您有2010版本,可以通过进入“开始”菜单\Programs\Microsoft Office 2010 Developer Resources\Microsoft Visio 2010 SDK\Microsoft Visio Code Samples Library来浏览示例。我相信您必须实现EvenSink才能访问“ShapeDeleted”,即 如果您正在查找事件“BeforeShapeDelete”,而不是“after”ShapeDelete;),则上述代码将对您有所帮助
(short)Microsoft.Office.Interop.Visio.VisEventCodes.visEvtCodeShapeDelete