Visio VBA功能可查看形状前面/后面是否有形状

时间:2020-03-06 14:56:24  来源:igfitidea点击:

在Visio VBA中,是否可以查看Visio中的形状前面还是后面的形状?

我想我可以写一些东西来检查页面中每个形状的边界框,以查看它是否与我的形状占用相同的空间。
我宁愿使用内置的东西,因为随着图形变得越来越多,检查每个形状可能会花费很长时间。

解决方案

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

在这里阅读更多:

MSDN上的Shape.SpatialRelation属性