Vb.net 分隔出多个动态创建的用户控件

Vb.net 分隔出多个动态创建的用户控件,vb.net,winforms,user-controls,Vb.net,Winforms,User Controls,所以我要做的就是创建我的usercontrol的多个实例 尽管我一直在寻找一种让它们彼此相邻的方法,比如在下一个之间创建一个5像素的空间。一种方法是使用一个动态计算它的函数。我还没有测试过这个,但它应该可以工作。您只需调用doGetAppExposition,它将循环遍历控件的所有实例,并将找到的最后一个实例作为下一个x位置 Dim App As New AppTab() With App ... .Location = New Point(doGetAppXPosition,

所以我要做的就是创建我的usercontrol的多个实例


尽管我一直在寻找一种让它们彼此相邻的方法,比如在下一个之间创建一个5像素的空间。

一种方法是使用一个动态计算它的函数。我还没有测试过这个,但它应该可以工作。您只需调用
doGetAppExposition
,它将循环遍历控件的所有实例,并将找到的最后一个实例作为下一个x位置

Dim App As New AppTab()
With App
    ...
    .Location = New Point(doGetAppXPosition, 5)
    ...
End With
Me.Controls.Add(App)

Private Function doGetAppXPosition() as Integer

    Dim xpos as Integer = 5
    For Each oControl As Control In YourForm.Controls
            If TypeOf oControl Is AppTab Then
                xpos = oControl.Right + 5
            End If
    Next

    Return xpos
End Function