在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属性

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top