Visio VBA function to see if there is a form in front of / behind the form

Is there a way in Visio VBA to see if there is a shape in front of or behind a shape in Visio?

I guess I could write something that checks the bounding box of each shape on the page to see if it occupies the same space as my shape. I would rather use something built-in, as checking each shape can take a lot of time, as the drawing gets more and more shapes.

+4
source share
1 answer

The Shape.SpatialRelation property will tell you whether two shapes are touching. The Shape.Index property will tell you what is in front or behind in z-order.

Here is a simple example:

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 

More details here:

Shape.SpatialRelation Property on MSDN

+3
source

Source: https://habr.com/ru/post/1277333/


All Articles