2008-09-30 50 views
4

Visio VBA中有沒有一種方法可以查看Visio中形狀的前面還是後面?Visio VBA函數查看在形狀前面或後面是否有形狀

我想我可以寫一些東西,檢查頁面中每個形狀的邊界框,看看它是否佔據與我的形狀相同的空間。 我寧願使用內置的東西,因爲檢查每個形狀可能需要很長時間,因爲繪圖的形狀越來越多。

回答

3

Shape.SpatialRelation屬性會告訴你兩個形狀是否接觸。 Shape.Index屬性會告訴你哪個在z順序的前面或後面。

下面是一個簡單的例子:

Public Sub DoShapesIntersect(ByRef shape1 As Visio.Shape, ByRef shape2 As Visio.Shape) 

    '// do they touch? 
    If (shape1.SpatialRelation(shape2, 0, 0) <> 0) Then 

     '// they touch, which one is in front? 
     If (shape1.Index > shape2.Index) Then 
      Debug.Print shape1.Name + " is in front of " + shape2.Name 
     Else 
      Debug.Print shape1.Name + " is behind " + shape2.Name 
     End If 
    Else 
     Debug.Print "shape1 and shape2 do not touch" 
    End If 

End Sub 

在這裏閱讀更多:

Shape.SpatialRelation Property on MSDN