How do Borders and Title shapes stretch to fit the page?

When dropping a border or title shape on a page, it automatically stretches to fit the page, but if you look at the shapesheet for the dropped shape, Width and Height are fixed. How do they do that?


The trick is that the shape on the stencil has an EventDrop cell that tells Visio to set the values of Width, Height, PinX and PinY to fixed values when the shape is dropped on a page. It also tells Visio to clear the EventDrop cell so the process can not be repeated by the copy.


You can find samples of these shapes by looking in the “Background” “Border and Titles” stencils. When you look ath these shapes, you will find that these shapes define their size based on the page size using the following formula:

Width =ThePage!PageWidth-4*User.PageMargin
Height=ThePage!PageHeight-4*User.PageMargin
PinX=ThePage!PageWidth*0.5
PinY=ThePage!PageHeight*0.5

The value for the PageMargin row in the User Section is a bit involved to repeat here, but it sets the margin off the shape based on the scaling factors in use.


The EventDrop cell uses SETF and GETF to assign the initial formula to the four cells and then replace it with the formulas value. I have broken the formula into its’ five components to make it more readable. In reality, the formula in the EventDrop cell below is one long string. 

=SETF(GetRef(Width),ThePage!PageWidth-4*User.PageMargin)
+SETF(GetRef(Height),ThePage!PageHeight-4*User.PageMargin)
+SETF(GetRef(PinX),ThePage!PageWidth*0.5)
+SETF(GetRef(PinY),ThePage!PageHeight*0.5)
+SETF(“EventDrop”,0)

 The final SETF clears the EventDrop cell.


A similar method is used for Background pages, but the formulas are not cleared


Width =GUARD(ThePage!PageWidth)
Height=GUARD(ThePage!PageHeight)
PinX=GUARD(Width/2)
PinY=GUARD(Height/2)


Unlike the Borders and Titles shapes, the Background shape needs to run an add-on to place the shape. The EventDrop cell contains:


=RUNADDON(“Make Background”)+SETF(“EventDrop”,0)


The “Make Background” is a Private add-on which will create a background page called VBackground, place and resize the shape and then add the background page reference to the foreground page.


John…    Visio MVP

Leave a Reply

Your email address will not be published. Required fields are marked *