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

Asked

Viewed 170 times

0

I am trying to open a form within another form, but I am having a certain difficulty.

The idea is that when the clicked on the button "btn_CadastroAlunos" the form "F_cadastro_alunos.Vb" is opened in the Panel1 that is present in the main form "F_principal.Vb"

My code is like this in the Button Click event ("btn_CadastroAlunos"):

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

But when executing the button click operation, the following error is returned:

System.Argumentexception: 'Only top-level controls can have an owner. Arg_paramname_name'

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

A imagem pode auxiliar no entendimento do meu problema

Does anyone know the solution?! Thank you for your attention!

Note: I am using the framework: Moden UI

1 answer

1

You won’t be able to do this with a form. I think it would be better to just 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 the Dexes. This gives a legal effect too.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.