Best way to display a form within another form?

Asked

Viewed 2,213 times

1

I’m in doubt here, I don’t know much about it.

1 I was wearing a form only, with several panel hidden within it, and when the user clicked on some option in the menuStrip I manipulated the properties Enabled and Visible of the corresponding panels. However, the database was not recording the typed content.

2 I tried using splitContainer, but still bug, not to save, but it takes a long time to get the form and to save. I tried with the code:

splitContainer1.Panel2.Controls.Clear(); // limpa o painel2
nvCli.TopLevel = false; // não alinha ao topo
nvCli.AutoScroll = true; // exibe barra de rolagem automaticamente
splitContainer1.Panel2.Controls.Add(nvCli); //add formulario ao painel 2
nvCli.Show(); // mostra formulario

Where nvCli is a static and public instance of another form. Another problem here is that the form was not being displayed in the center of the panel2, was getting bent.

I was wondering if there is a better way to display or how to solve the bugs?

Interface layout (yes, I did in Paint kk) inserir a descrição da imagem aqui

2 answers

1

It had a medium solution in the gambiarra style, it is only you leave the elements that should appear when the form is started visible and the rest (this hidden form) must be invisible (Visible=false), and when the user clicks on this menustrip these elements would be visible.

It’s a very "manual" and "inelegant" solution, but why have an elegant code anyway? Just make sure everything works and you’ll understand everything later, in case you need to maintain the code.

  • For that I was using the panel, to 'group' these elements... I am now using slipContainer, because it was the option that I found more ideal (I solved the bugs that happened)

1

Hello, Leonardo. All right?

I find it not very advantageous to use several Foms within another, besides making the interface very complex, tends to make the code quite extensive.

Do you have a really good reason for doing this? If not, I advise you to use Forms with Showmodal even, as long as they don’t get too many overlapping, or even keep several panels hidden and display them when necessary.

The error of not saving in the bank needs to be evaluated as it is probably not related to panels.

  • I have no reason, it’s simply because I don’t know anything to do it, my goal is to show a form (database table, or database fields) different by clicking on an option from the strip menu, example, when clicking register displays the registration form there in the "form here" (I added an image of my layout in the post), then when he click on another option he disappears with the one that is active and displays the form of the other

  • Leonardo, for this type of scenario, analyze if using the MDI strategy would not be appropriate. There is a lot of material on MDI applications on the Internet.

Browser other questions tagged

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