Windows Forms and Panels

Asked

Viewed 256 times

0

How to use a single form to present several screens, such as login, registration, administration, etc?

It is possible using the panel component, but the rendering of it is slow, besides being unpleasant to develop in this way.


I may be talking nonsense, but I imagine a solution something like this.

frmPrincipal = Contains Windows Form with fixed components.

duvLogin = Contains the visual components that will be activated in the frmPrincipal when requested.

duvRegistro = Contains the visual components that will be activated in the frmPrincipal when requested.

I would like to know the correct or most suitable way to organize the screens in the form.

2 answers

1

The best then is to use the property IsMdiContainer from the main form. Set it to true.

In other (internal) Forms, you use the property MdiParent (defined in code before the show()).

So you only have a main screen and other internal screens. I will post a link with detailed tutorial for more information:

http://www.macoratti.net/09/08/c_mdi1.htm


For the specific case of login screen, I recommend that you use another form, hiding the first one, opening and displaying the second one and closing the first one (in that order). For the others use the case cited above.

0

You can use the UserControl to build the components of login, registration and etc... and add in the main form the corresponding control.

Creates a UC login and other record and in the main form you add a panel to load the UCs:

for the code below imagine the following situation:

Main form:

  1. painel_principal;

Users Control;

  1. UC login;

  2. UC Registro;


private UC_login uc_login=new UC_login ();
private UC_Registro uc_registro=new UC_Registro ();

public void TrocarUC(string controle)
{
   panel_principal.Controls.Clear();
   if(controle=="login")
   {
      panel_principal.Controls.Add(uc_login);
   }
   else if(controle=="registro")
   {
       panel_principal.Controls.Add(uc_registro);
   }
}

Browser other questions tagged

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