2008-09-30 51 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