VB2008在运行时创建重复的现有表单

时间:2015-08-09 07:52:44

标签: vb.net

嗨我想在运行时复制现有表单,以便可以多次使用。有单一的方式,如

Sub loadForm()
    Dim childForm As New myForm '<--- 
    With childForm
        .TopLevel = False
        .StartPosition = FormStartPosition.CenterScreen
        .Top = 199
        .BringToFront()
        Panel1.Controls.Add(childForm)
        .Show()
    End With
End Sub

但是我希望那个表格应该重复参考我试过

Sub LoadForm(ByVal childForm As Form)       
    'where childForm can be any myform1/mysale/mypurchase etc.
    With childForm
        .TopLevel = False
        .StartPosition = FormStartPosition.CenterScreen
        .Top = 199
        .BringToFront()
        Panel1.Controls.Add(childForm)
        .Show()
    End With
End Sub

我打电话

LoadForm(myform1)
LoadForm(mysale)

这不重复我也尝试创建

Dim newChildForm as new childForm ' its give error 1 Type 'childForm' not defined

1 个答案:

答案 0 :(得分:0)

感谢GSerg提示

问题解决 我需要做的就是替换

loadForm(myform)

loadForm(New myform)