我正在尝试添加嵌套容器的层次结构。我希望能够将子容器(B)添加到给定容器(A)中,该容器可能具有其他子容器(C),因此B和C将与另一个容器相邻。
我遇到了B嵌套在C中的问题。我想要的是B和C在A中,但不在彼此之内。
这是我的代码:
Sub Main()
Dim shape As Visio.shape
Dim cont As Container
Set cont = New Container
cont.InitializeClass "KeyA", "A"
cont.AddSubcontainer "KeyB", "B"
cont.AddSubcontainer "KeyC", "C"
End Sub
我有一个类容器
Option Explicit
Private mName As String
Private mKey As String
Private mContainerShape As Visio.shape
Private mSubcontainers 'Dictionary
Private mX_coord As Double
Private mY_coord As Double
...
Private Sub Class_Initialize()
Set mContainerShape = createContainer()
Set mSubcontainers = CreateObject("Scripting.Dictionary")
End Sub
Public Sub InitializeClass(pKey As String, pName As String)
'Initialize with Setter so that container text title will be set too
Me.key = pKey
Me.Name = pName
End Sub
Public Function createContainer(Optional shape As Visio.shape = Nothing) As Visio.shape
Dim Container As Visio.shape
Dim doc As Visio.Document
Set doc = Application.Documents.OpenEx(Application.GetBuiltInStencilFile(visBuiltInStencilContainers, visMSUS), visOpenHidden)
Set createContainer = Application.ActivePage.DropContainer(doc.Masters.ItemFromID(2), shape)
doc.Close
End Function
Public Function AddSubcontainer(subKey As String, subName As String)
Dim subcontainerKey As String
Dim subcontainer As Container
Dim subcontainerShape As Visio.shape
Dim subcontainer_row As Integer
subcontainerKey = mKey & subKey
Set subcontainer = New Container
subcontainer.InitializeClass subcontainerKey, subName
Set subcontainerShape = subcontainer.ContainerShape
subcontainer_row = subcontainerShape.AddRow(visSectionProp, visRowLast, visTagDefault)
With mContainerShape
.ContainerProperties.AddMember subcontainerShape, visMemberAddExpandContainer
.ContainerProperties.FitToContents
End With
mSubcontainers.Add subcontainerKey, subcontainer
End Function
我认为问题发生在AddSubcontainer()中的AddMember调用中。即使它将一个成员添加到容器A中,它似乎也会将其粘贴在B中。