0

hi i want to duplicate existing form on runtime so it can be use multiple times. there is single way like

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

but what i want that form should be duplicate with reference i tried

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

where i call

LoadForm(myform1)
LoadForm(mysale)

this does not duplicate i also tried to create

Dim newChildForm as new childForm ' its give error 1 Type 'childForm' not defined
mortypk
  • 46
  • 1
  • 11
  • Visual Basic allows you to [use the type name of a form as a variable](http://stackoverflow.com/q/6048889/11683) that magically holds an implicitly created instance of that form. You should not use this feature. Always create instances of your forms with `New` and never refer to an instance using its type name. If that alone does not solve your problem, then please clarify. – GSerg Aug 09 '15 at 08:12
  • There is no obvious attempt at "duplicating" in these snippets. Can't work anyway, you can't clone form objects. You'd need `New myForm1` to create another instance. Most obvious flaw here is that you display the forms in the exact same Location, you only see the top one. Use, say, a FlowLayoutPanel instead. Or pick a proper Location. – Hans Passant Aug 09 '15 at 08:23
  • hans-passant display location is fixed but i drag that form and call LoadForm it will relocate form which i have draged. – mortypk Aug 09 '15 at 09:16

1 Answers1

0

Thanks GSerg for the Hint

problem solve all i need to do is replace

loadForm(myform)

with

loadForm(New myform)
mortypk
  • 46
  • 1
  • 11