Window.Selection 属性 (Visio)

返回代表窗口中的目前选定内容的 Selection 对象,或者将由 CreateSelection 方法创建的选定内容指派给 Selection 对象。 读/写。

语法

表达式选择

表达 一个代表 Window 对象的变量。

返回值

选择

备注

Selection 对象独立于窗口中的选定内容,选定内容随后可能会由于用户动作而发生更改。

Selection 对象是可在公共上下文中执行操作的一组形状。 Selection 对象类似于绘图窗口中的多个选定形状。 设置或检索 Selection 对象后,可以使用 Select 方法更改对象表示的形状集。

使用 CreateSelection 方法创建选定内容后,您就可以使用 Selection 属性在 Microsoft Visio 绘图窗口中实际显示新创建的选定内容。 请参阅下面的第二个示例。

示例

以下 Microsoft Visual Basic for Applications (VBA) 宏显示如何使用 Selection 属性获取窗口中的所有选定形状。

Public Sub Selection_Example() 
 
 Const MAX_SHAPES = 6 
 Dim vsoShapes(1 To MAX_SHAPES) As Visio.Shape 
 Dim vsoSelection As Visio.Selection 
 Dim intCounter As Integer 
 
 'Draw six rectangles. 
 For intCounter = 1 To MAX_SHAPES 
 Set vsoShapes(intCounter) = ActivePage.DrawRectangle(intCounter, intCounter + 1, intCounter + 1, intCounter) 
 Next intCounter 
 
 'Deselect all the shapes in the active window. 
 ActiveWindow.DeselectAll 
 
 'Select all the shapes in the active window. 
 ActiveWindow.SelectAll 
 
 'Get the selected shapes and assign them to a Selection object. 
 Set vsoSelection = ActiveWindow.Selection 
 
End Sub

以下 VBA 宏显示如何使用 CreateSelection 方法选择特定图层上的所有形状。 然后,它使用 Selection 属性在 Visio 绘图窗口中显示所选内容。

在运行此宏之前,请在绘图中创建两个层,一个名为“a”,一个名为“b”,然后将形状添加到这两个层。

Public Sub Selection_Example_2() 
 
 Dim vsoLayer As Layer 
 Dim vsoSelection As Visio.Selection 
 
 Set vsoLayer = ActivePage.Layers.ItemU("a") 
 Set vsoSelection = ActivePage.CreateSelection(visSelTypeByLayer, visSelModeSkipSuper, VsoLayer) 
 
 Application.ActiveWindow.Selection = vsoSelection 
 
End Sub

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。