Window.Select 方法 (Visio)

會選取或清除物件。

語法

運算式 (SheetObjectSelectAction)

表達 代表 Window 物件的變數。

參數

名稱 必要/選用 資料類型 描述
SheetObject 必要 [IVSHAPE] 會傳回要選取或清除之 Shape 物件的運算式。
SelectAction 必要 整數 要採取的選取動作類型。

傳回值

註解

搭配 Window 物件使用時, Select 方法會影響 Microsoft Visio 視窗中的選取範圍。 不過, Selection 物件與視窗中的選取範圍無關。 因此,搭配 Selection物件使用Select方法只會影響記憶體中物件的狀態;Visio 視窗不受影響。

下列由 Visio 型別程式庫以 VisSelectArgs 宣告的常數,會顯示對選取類型有效的值。

常數 描述
visDeselect 1 會取消選取圖形,但是讓選取範圍的其餘部分維持不變。
visSelect 2 會選取圖形,但是讓選取範圍的其餘部分維持不變。
visSubSelect 3 會選取已經選取其父系的圖形。
visSelectAll 4 會選取圖形及其所有對等項目。
visDeselectAll 256 會取消選取圖形及其所有對等項目。

如果 SelectAction 為 visSubSelect,則必定已經選取 SheetObject 的父系圖形。

您可以將 visDeselectAllvisSelectvisSubSelect 合併在一起,以便在選取或後續選取其他圖形之前,清除所有的圖形。

如果操作所在的物件是 Selection 物件,而且 Select 方法選取了 Shape 物件 (此物件的 ContainingShape 屬性與 Selection 物件的 ContainingShape 屬性不同),則 Select 方法會清除所有項目,即使在選取類型值未指定取消選取時,也是如此。

如果操作所在的物件是 Window 物件,而且 SelectAction 不是 visSubSelect,則 SheetObject 的父系圖形必須是 Window.Selection 物件的 ContainingShape 屬性傳回的同一個圖形。

如果您的 Visual Studio 解決方案包含 Microsoft.Office.Interop.Visio 參考,此方法會對應至下列類型:

  • Microsoft.Office.Interop.Visio.IVWindow.Select (Microsoft.Office.Interop.Visio.Shape, short)

範例

這個 Microsoft Visual Basic for Applications (VBA) 巨集將示範如何選取、清除及後續選取圖形。

 
Public Sub Select_Example()  
 
    Const MAX_SHAPES = 6  
    Dim vsoShapes(1 To MAX_SHAPES) As Visio.Shape  
    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  
 
    'Cancel the selection of all the shapes on the page.  
    ActiveWindow.DeselectAll  
 
     'Create a Selection object. 
    Dim vsoSelection As Visio.Selection  
    Set vsoSelection = ActiveWindow.Selection  
 
    'Select the first three shapes on the page. 
    For intCounter = 1 To 3  
        vsoSelection.Select vsoShapes(intCounter), visSelect  
    Next intCounter  
 
    'Group the selected shapes.  
    'Although the first three shapes are now grouped, the  
    'array vsoShapes() still contains them. 
    Dim vsoGroup As Visio.Shape  
    Set vsoGroup = vsoSelection.Group 
 
    'There are now four shapes on the page: a group that contains three  
    'subshapes, and three ungrouped shapes. Subselection is  
    'accomplished by selecting the parent shape first or one of the  
    'group's shapes already subselected.  
 
    'Select parent (group) shape. 
    ActiveWindow.Select vsoGroup, visDeselectAll + visSelect  
 
    'Subselect two of the shapes in the group. 
    ActiveWindow.Select vsoShapes(1), visSubSelect  
    ActiveWindow.Select vsoShapes(3), visSubSelect  
 
     'At this point two shapes are subselected, but we want to  
    'start a new selection that includes the last two shapes  
    'added to the page and the group. 
 
    'Note that the subselections that were made in the group  
    'are canceled by selecting another shape that is 
    'at the same level as the parent of the subselected shapes.  
 
    'Select just one shape. 
     ActiveWindow.Select vsoShapes(MAX_SHAPES), _  
        visDeselectAll + visSelect  
 
    'Select another shape. 
    ActiveWindow.Select vsoShapes(MAX_SHAPES - 1), visSelect  
 
    'Select the group.  
    ActiveWindow.Select vsoGroup, visSelect  
 
    'Select all but one shape on the page.  
    ActiveWindow.SelectAll  
    ActiveWindow.Select vsoShapes(MAX_SHAPES - 1), visDeselect  
 
End Sub

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應