Error opening a form inside another form [VB.NET]

0

I'm trying to open a form inside another form, but I'm having some difficulty.

The idea is that when you click on the "btn_CadastroAlunos" button the form "F_Cadastro_Alunos.vb" opens in panel1 that is present in the main form "F_Principal.vb"

My code looks like this in the Click event of the button ("btn_CadastroAlunos"):

    Dim NovoForm As New F_Cadastro_Alunos
    NovoForm.TopLevel = False
    NovoForm.Visible = True
    Panel1.Controls.Add(NovoForm)
    NovoForm.Show()

However, when you perform the button click operation, the following error is returned:

  

System.ArgumentException: 'Only the top-level controls can have an owner.   Arg_ParamName_Name '

The following image explains the error generated when trying to display the form:

Does anyone know what the solution is ?! Thanks in advance for your attention!

Note: I am using the framework: Moden UI

    
asked by anonymous 02.11.2018 / 03:03

1 answer

0

You will not be able to do this with a form. I think it would be best to simply open the form and use NovoForm.Location = New System.Drawing.Point(0, 0)

Just replace the zeros with the location you want. Or you can use a TabControl, and change between indexes. This gives a legal effect as well.

    
14.11.2018 / 03:31