Table of contents
TOC
折叠目录
展开目录

Application.ShapeAdded 事件 (Visio)Application.ShapeAdded Event (Visio)

office 365 dev account|上次更新日期: 2018/3/13
|
2 参与人员

在将一个或多个形状添加到文档之后,发生此事件。Occurs after one or more shapes are added to a document.

语法Syntax

专用子_表达式__ShapeAddedByVal 形状为 [IVSHAPE]Private Sub expressionShapeAdded( **_ByVal Shape As [IVSHAPE]** )

表达式_一个表示应用程序对象的变量。_expression A variable that represents an Application object.

参数Parameters

名称Name必需/可选Required/Optional数据类型Data Type说明Description
形状Shape必需Required[IVSHAPE][IVSHAPE]已添加到文档的形状或形状组。The shape or group of shapes that was added to the document.

注解Remarks

如果该形状的类型属性为visTypeGroup (2) 或visTypePage (1),一个Shape对象可以作为ShapeAdded事件的源对象。A Shape object can serve as the source object for the ShapeAdded event if the shape's Type property is visTypeGroup (2) or visTypePage (1).

SelectionAddedShapeAdded事件很相似,在于它们都激发后创建的形状。它们在单个操作添加多个形状时它们的行为方式上存在差异。假设一个粘贴操作创建三个新形状。ShapeAdded事件触发三次,每三个对象的作用。SelectionAdded事件将触发一次,且在Selection对象中选定的三个新形状。The SelectionAdded and ShapeAdded events are similar in that they both fire after shape(s) are created. They differ in how they behave when a single operation adds several shapes. Suppose a Paste operation creates three new shapes. The ShapeAdded event fires three times and acts on each of the three objects. The SelectionAdded event fires once, and it acts on a Selection object in which the three new shapes are selected.

若要确定是否ShapeAdded事件将由新形状或一组形状被添加到页中,通过一套现有形状进行分组,或粘贴操作,您可以使用Application.IsInScope属性触发。如果传递的visCmdObjectGroupShapeAdded事件触发由分组操作时, IsInScope将返回True 。如果IsInScope返回True时传递visCmdUFEditPastevisCmdEditPasteSpecialShapeAdded事件被触发的粘贴操作。如果IsInScope返回False传递所有这些参数时,新形状添加到页面必须被触发该事件。To determine if a ShapeAdded event was triggered by a new shape or group of shapes being added to the page, by a set of existing shapes being grouped, or by a paste action, you can use the Application.IsInScope property. If IsInScope returns True when passed visCmdObjectGroup , the ShapeAdded event was triggered by a grouping action. If IsInScope returns True when passed visCmdUFEditPaste or visCmdEditPasteSpecial , the ShapeAdded event was triggered by a paste operation. If IsInScope returns False when passed all of these arguments, the event must have been triggered by new shapes being added to the page.

如果您使用 Microsoft Visual Basic 或 Visual Basic for Applications (VBA),则此主题中的语法描述的是一种通用而有效的事件处理方法。If you are using Microsoft Visual Basic or Visual Basic for Applications (VBA), the syntax in this topic describes a common, efficient way to handle events.

如果您想要创建您自己的事件对象,使用添加AddAdvise方法。若要创建一个事件对象,运行加载项,请使用Add方法,应用到事件列表集合。若要创建一个事件对象,该对象接收通知,请使用AddAdvise方法。若要查找您想要创建的事件的事件代码,请参阅事件代码If you want to create your own Event objects, use the Add or AddAdvise method. To create an Event object that runs an add-on, use the Add method as it applies to the EventList collection. To create an Event object that receives notification, use the AddAdvise method. To find an event code for the event you want to create, seeEvent codes.

示例Example

此 VBA 示例说明了如何进行计数基于名为正方形的主控的形状添加到绘图。将代码粘贴到活动文档的项目中,Visio。This VBA example shows how to count shapes added to a drawing that are based on a master called Square. Paste the code into the active document's project in Visio.

在保存活动文档时, DocumentSaved事件处理程序运行。该处理程序初始化整型变量, intNumberOfSquares ,用于存储该计数。The DocumentSaved event handler runs when the active document is saved. The handler initializes an integer variable, intNumberOfSquares , which is used to store the count.

ShapeAdded事件处理程序运行一个形状添加到绘图页上,每次无论该形状从模具中使用绘图工具绘制还是从剪贴板中粘贴拖动。该处理程序将检查新形状的主控形状属性,并如果该形状基于正方形母版上,增加_intNumberOfSquares_ 。The ShapeAdded event handler runs each time a shape is added to the drawing page, whether the shape is dragged from a stencil, drawn with a drawing tool, or pasted from the Clipboard. The handler checks the Master property of the new shape and, if the shape is based on the Square master, increments intNumberOfSquares .


Dim intNumberOfSquares As Integer 

Private Sub Document_DocumentSaved(ByVal vsoDocument As Visio.IVDocument) 

 'Initialize number of squares added. 
 intNumberOfSquares = 0 

End Sub 

Private Sub Document_ShapeAdded(ByVal vsoShape As Visio.IVShape) 

 Dim vsoMaster As Visio.Master 

 'Get the Master property of the shape. 
 Set vsoMaster = vsoShape.Master 

 'Check whether the shape has a master. If not, 
 'the shape was created locally. 
 If Not (vsoMaster Is Nothing) Then 

 'Check whether the master is "Square". 
 If vsoMaster.Name = "Square" Then 

 'Increment the count for the number of squares added. 
 intNumberOfSquares = intNumberOfSquares + 1 

 End If 

 End If 

 MsgBox "Number of squares: " &; intNumberOfSquares, vbInformation, _ 
 "Document Created Example" 

End Sub
© 2018 Microsoft